Thrift 各種服務端和客戶端實現

2021-07-25 19:35:20 字數 3374 閱讀 3311

//簡單的單執行緒服務模型

import org.apache.thrift.texception;

import org.apache.thrift.tprocessor;

import org.apache.thrift.protocol.tbinaryprotocol;

import org.apache.thrift.server.tserver;

import org.apache.thrift.server.t******server;

import org.apache.thrift.transport.tserversocket;

import org.apache.thrift.transport.ttransportexception;

public class hellot******server

public static void main(string args) throws texception

}

import org.apache.thrift.texception;

import org.apache.thrift.protocol.tbinaryprotocol;

import org.apache.thrift.protocol.tprotocol;

import org.apache.thrift.transport.tsocket;

import org.apache.thrift.transport.ttransport;

public class helloclient

}

//執行緒池服務模型,使用標準的阻塞式io,預先建立一組執行緒處理請求。

import org.apache.thrift.texception;

import org.apache.thrift.tprocessor;

import org.apache.thrift.protocol.tbinaryprotocol;

import org.apache.thrift.server.tthreadpoolserver;

import org.apache.thrift.transport.tserversocket;

import org.apache.thrift.transport.ttransportexception;

public class hellotthreadpoolserver

public static void main(string args) throws texception

}

客戶端不變

//使用非阻塞式io,服務端和客戶端需要指定 tframedtransport 資料傳輸的方式。

import org.apache.thrift.texception;

import org.apache.thrift.tprocessor;

import org.apache.thrift.protocol.tcompactprotocol;

import org.apache.thrift.server.tnonblockingserver;

import org.apache.thrift.server.tserver;

import org.apache.thrift.transport.tframedtransport;

import org.apache.thrift.transport.tnonblockingserversocket;

import org.apache.thrift.transport.ttransportexception;

public class hellotnonblockingserver

public static void main(string args) throws texception

}

import org.apache.thrift.texception;

import org.apache.thrift.protocol.tcompactprotocol;

import org.apache.thrift.protocol.tprotocol;

import org.apache.thrift.transport.tframedtransport;

import org.apache.thrift.transport.tsocket;

import org.apache.thrift.transport.ttransport;

public class helloclient

}

//半同步半非同步的服務端模型,需要指定為: tframedtransport 資料傳輸的方式。

import org.apache.thrift.texception;

import org.apache.thrift.tprocessor;

import org.apache.thrift.protocol.tbinaryprotocol;

import org.apache.thrift.server.thshaserver;

import org.apache.thrift.server.tserver;

import org.apache.thrift.transport.tframedtransport;

import org.apache.thrift.transport.tnonblockingserversocket;

import org.apache.thrift.transport.ttransportexception;

public class hellothshaserver

public static void main(string args) throws texception

}

import org.apache.thrift.texception;

import org.apache.thrift.protocol.tbinaryprotocol;

import org.apache.thrift.protocol.tprotocol;

import org.apache.thrift.transport.tframedtransport;

import org.apache.thrift.transport.tsocket;

import org.apache.thrift.transport.ttransport;

public class helloclient

}

Python UDP客戶端 服務端

udpclient.py coding utf 8 from socket import servername 127.0.0.1 伺服器位址,本例中使用一台遠端主機 serverport 12000 伺服器指定的埠 clientsocket socket af inet,sock dgram 建立...

python udp客戶端,服務端

客戶端1 建立套接字 2 收發資料 3 關閉套接字 import socket 建立套接字 socket socket.socket socket.af inet,socket.sock dgram 傳送資料 傳送資料的型別必須是位元組型別 data 你猜 encode gbk addr 192.1...

udp服務端 客戶端

個數 2的16次方 埠是資料發出或接收的入口 埠的目的 通過埠號找到對應的程序,完成資料的通訊 著名埠0 1023 這是建立了乙個基於udp協議的服務端 import socket todo 1.0 建立了乙個套接字,用來連線客戶端,傳送與接收資料 udp server socket.socket ...