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 ...
随机推荐
- <每日一题>题目26:选择排序(冒泡排序改进版)
''' 选择排序:选择最小的,以此类推 ''' import random import cProfile def select_Sort(nums): for i in range(len(nums ...
- springcloud(二):Eureka服务注册与发现
Spring Cloud Netflix 该项目是Spring Cloud的子项目之一,主要内容是对Netflix公司一系列开源产品的包装,它为Spring Boot应用提供了自配置的Netflix ...
- Activiti工作流 安装myeclipse activiti设计插件并生成数据库表
从零开始学习Activiti工作流,记录下学习过程. 关于工作流的简介没什么好介绍了,只能说是个很有用的东西,数据库中23张表分别有什么用网上也有很详细的介绍,这里也不多加说明.activiti开发中 ...
- 使用springmvc实现文件上传
该配置在javaweb上传文件篇中的基础上进行配置:https://www.cnblogs.com/flypig666/p/11745182.html 1.配置文件解析器,在springmvc.xml ...
- 初识css3 3d动画效果
(先看我博客右上角的3d盒子动画效果,目前没做兼容处理,最好最新的chrome看)无意间看到网上css3写的3d动画效果,实在炫酷,以前理解为需要js去计算去写,没想到css直接可以实现.于是开始研究 ...
- 洛谷P2333 [SCOI2006]一孔之见
传送门 辣鸡题目毁我人生败我前程 50分代码 //Achen #include<algorithm> #include<iostream> #include<cstrin ...
- MyBatis配置文件(二)--settings配置
settings是MyBatis中最复杂的配置,它能影响MyBatis底层的运行,大部分情况下使用默认值,只需要修改一些常用的规则即可.常用规则有自动映射.驼峰命名映射.级联规则.是否启动缓存.执行器 ...
- PAT甲级——A1064 Complete Binary Search Tree
A Binary Search Tree (BST) is recursively defined as a binary tree which has the following propertie ...
- ajax返回后台编译时都对,返回error
首先看看你的dataType:‘json’ 类型是否与后台获取的类型一直.特别是json的格式对不对. 第二: 红括号里的有没有加
- java mybatis 参数问题