php thrift TServerSocket实现端口复用
<?php
namespace Message\Controller;
use Think\Controller;
use Thrift\Exception\TException;
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TBufferedTransport;
use Thrift\Transport\THttpClient;
use Thrift\Transport\TPhpStream;
use Thrift\TMultiplexedProcessor;
use Thrift\Protocol\TMultiplexedProtocol;
use Message\Services\MessageServie;
use Rpc\Msg\MessageClient;
use Rpc\Msg\MessageProcessor;
use Thrift\Factory\TBinaryProtocolFactory;
use Thrift\Factory\TTransportFactory;
use Thrift\Server\TServerSocket;
use Thrift\Server\TSimpleServer;
use Thrift\Server\TForkingServer;
use Thrift\Transport\TSocket;
server
public function message_rpc()
{
try {
// 初始化多个服务提供者handle
$messageprocessor = new \Rpc\Msg\MessageProcessor(new MessageServie());
// 创建多个服务Processor
$sendProcessor = new \Rpc\Msg\SendMsgProcessor(new \Message\Services\SendMsgServie()); // 将服务注册到TMultiplexedProcessor中
$tFactory = new TTransportFactory();
$pFactory = new TBinaryProtocolFactory(true, true);
$processor = new TMultiplexedProcessor();
// 将服务注册到TMultiplexedProcessor中
//队列消费者rpc请求
$processor->registerProcessor("MessageApiAction", $messageprocessor);
//消息发送rpc请求
$processor->registerProcessor("sendMsg", $sendProcessor); // 初始化数据传输方式transport
// 利用该传输方式初始化数据传输格式protocol // 监听开始
$transport = new TServerSocket('0.0.0.0', ''); // $processor->process($pFactory, $pFactory); $server = new TForkingServer($processor, $transport, $tFactory, $tFactory, $pFactory, $pFactory);
$server->serve();
} catch (TException $tx) {
\Think\Log::write($tx->getMessage());
} catch(\Exception $e){
\Think\Log::write($e->getMessage());
}
}
client
public function local()
{
try {
ini_set('memory_limit', '1024M');
$socket = new TSocket('192.168.1.188', '');
$socket->setRecvTimeout();
$socket->setDebug(true);
$transport = new TBufferedTransport($socket, , );
$protocol = new TBinaryProtocol($transport); $client = new MessageClient(new TMultiplexedProtocol($protocol, "MessageApiAction"));
// $client = new MessageClient($protocol);
$transport->open();
$result = $client->MessageApiAction('message api');
print_r($result);
$transport->close();
} catch (TException $tx) {
print_r($tx->getMessage());
} } public function send_msg()
{
try {
ini_set('memory_limit', '1024M');
$socket = new TSocket('192.168.1.188', '');
$socket->setRecvTimeout();
$socket->setDebug(true);
$transport = new TBufferedTransport($socket, , );
$protocol = new TBinaryProtocol($transport); $client = new \Rpc\Msg\SendMsgClient(new TMultiplexedProtocol($protocol, "sendMsg")); // $client = new \Rpc\Msg\SendMsgClient($protocol);
$transport->open();
$result = $client->sendMsg('send msg');
print_r($result);
$transport->close();
} catch (TException $tx) {
print_r($tx->getMessage());
} }
php thrift TServerSocket实现端口复用的更多相关文章
- python thrift 实现 单端口多服务的过程
Thrift 是一种接口描述语言和二进制通信协议.以前也没接触过,最近有个项目需要建立自动化测试,这个项目之间的微服务都是通过 Thrift 进行通信的,然后写自动化脚本之前研究了一下. 需要定义一个 ...
- 【 socke】C# socket端口复用-多主机头绑定
什么是端口复用: 因为在winsock的实现中,对于服务器的绑定是可以多重绑定的,在确定多重绑定使用谁的时候,根据一条原则是谁的指定最明确则将包递交给谁,而且没有权限之分.这种多重绑定便称之为端口复用 ...
- 在C#中实现Socket端口复用
转载:http://www.csharpwin.com/csharpspace/68.shtml 一.什么是端口复用: 因为在winsock的实现中,对于服务器的绑定是可以多重绑定的,在 ...
- 转载:C# socket端口复用-多主机头绑定
什么是端口复用: 因为在winsock的实现中,对于服务器的绑定是可以多重绑定的,在确定多重绑定使用谁的时候,根据一条原则是谁的指定最明确则将包递交给谁,而且没有权限之分.这种多重绑定便称之为端口复用 ...
- Linux:TCP状态/半关闭/2MSL/端口复用
TCP状态 CLOSED:表示初始状态. LISTEN:该状态表示服务器端的某个SOCKET处于监听状态,可以接受连接. SYN_SENT:这个状态与SYN_RCVD遥相呼应,当客户端SOCKET执行 ...
- TCP套接字端口复用SO_REUSEADDR
下面建立的套接字都是tcp套接字 1.进程创建监听套接字socket1,邦定一个指定端口,并接受了若干连接.那么进程创建另外一个套接口socket2,并试图邦定同一个端口时候,bind错误返回“Add ...
- 端口复用技术简单了解;重用端口;socket复用端口
端口复用相关点 多个应用复用端口,只有最后一个绑定的socket可以接受数据,所有socket都可以发送数据 使用端口复用技术时,所有的socket都开启端口复用,才可以实现端口复用 黑客技术,使用标 ...
- socket端口复用问题一二
实际上,默认的情况下,如果一个网络应用程序的一个套接字 绑定了一个端口( 占用了 8000 ),这时候,别的套接字就无法使用这个端口( 8000 ), 验证例子如下: #include <std ...
- Netscaler的超高端口复用助力应对公网地址紧张
Netscaler的超高端口复用助力应对公网地址紧张 http://blog.51cto.com/caojin/1898351 经常会有人问一个IP只有65535(姑且不考虑预留端口),从Big-ip ...
随机推荐
- 使用HTTP代理
HTTP代理服务器可以比作客户端与Web服务器网站之间的一个信息中转站,客户端发送的HTTP请求和Web服务器返回的HTTP响应通过代理服务器转发给对方, 爬虫程序在爬取某些网站的时候也需要使用代理, ...
- .net面试问题总结
原文://http://blog.csdn.net/wenyan07/article/details/41541489 用.net做B/S结构的系统,您是用几层结构来开发,每一层之间的关系以及为什么要 ...
- 记录:vue结合springboot进行分页查询和按条件进行查询
界面: 主要代码: 搜索框: <el-form ref="searchForm" :inline="true" :model="searchMa ...
- Gym-102141E
https://vjudge.net/problem/Gym-102141E 用set乱搞 #include<iostream> #include<cstdio> #inclu ...
- ASCII、Unicode、UTF-8 字符串和编码
字符编码 我们已经讲过了,字符串也是一种数据类型,但是,字符串比较特殊的是还有一个编码问题. 因为计算机只能处理数字,如果要处理文本,就必须先把文本转换为数字才能处理.最早的计算机在设计时采用8个比特 ...
- SolrCloud4.7.1分布式部署
一.环境 软件: apache-tomcat-7.0.53.tar.gz solr-4.7.1.tgz zookeeper-3.4.6.tar.gz 规划: 三个节点IP: 192.168.50. ...
- ssh小知识
1.查看系统在线用户 [root@testdb ~]# w 14:30:26 up 38 days, 21:22, 3 users, load average: 0.00, 0.01, 0.05USE ...
- PAT甲级——A1046 Shortest Distance
The task is really simple: given N exits on a highway which forms a simple cycle, you are supposed t ...
- matlab保存数据
一:存txt文件,用dlmwrite()dlmwrite 将一个矩阵写到由分隔符分割的文件中. 在保存整数到文件时使用save存为ascii文件时,常常是文件里都是实型格式的数据(有小数点,和后面很多 ...
- 时间格式的时间 转json的时候变成正常的string时间20170519
public class JsonDateValueProcessor implements JsonValueProcessor { private String format ="yyy ...