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 ...
随机推荐
- GitHub:如何构建一个股票市场知识图谱?(附代码&链接)
来源:专知 本文约 600007 董事⻓/董事 高燕 女 60 600007 执⾏董事 刘永政 男 50 600008 董事⻓/董事 ··· ··· ··· ··· ··· 注:建议表头最好用相应的英 ...
- java笔试之计算n x m的棋盘格子
请编写一个函数(允许增加子函数),计算n x m的棋盘格子(n为横向的格子数,m为竖向的格子数)沿着各自边缘线从左上角走到右下角,总共有多少种走法,要求不能走回头路,即:只能往右和往下走,不能往左和往 ...
- Ubuntu 16.04 安装STS
先将STS下载下来,网址是 https://spring.io/tools/sts/all ,然后将STS压缩包移动或者copy到想要放置的位置,比如, sudo cp spring-tool-sui ...
- HZOI20190813 B,任(duty)
题面:去一个神奇的网页:https://www.cnblogs.com/Juve/articles/11352426.html 听说打O(nmq)有70 但是显然博主只有50分 考点:前缀和的综合应用 ...
- 常用的git操作命令
整理来源于廖雪峰的git教程https://www.liaoxuefeng.com git: 分布式版本控制系统 本地有完整的代码库,还有远程代码库 svn: 集中式版本控制系统 必须联网时才可提交 ...
- HDU 6003 Problem Buyer
贪心题(好久不做了) 题解 考虑最一般的,判断合法性? 经典贪心问题:左端点升序,左端点相同,右端点降序,c[i]升序 优先队列,每次选择覆盖x的右端点最小的区间. 称此方法为“区间匹配贪心” 最小的 ...
- hibernate 一对一注解
bi如 用户的阅读历史和文章表是单向一对一关系, 阅读历史中通过deviceId外键关联文章表的主键 然后,再从getter setter上进行注解 @OneToOne(cascade = Casca ...
- 数据交换格式之 - Json
Json简介: JSON是JavaScript对象表示法,是一种与语言无关的数据交换的格式,是一种完全独立于语言的文本格式. 使用ajax进行前后台数据交换,移动端与服务端的数据交换. web客户端和 ...
- jsonp 请求报Uncaught SyntaxError: Unexpected token :
$(document).ready(function() { jQuery.ajax({ type: 'GET', url: 'http://wncrunners.com/admin/colors.j ...
- 2019-3-8-win10-uwp-一张图说明水平对齐和垂直对齐
title author date CreateTime categories win10 uwp 一张图说明水平对齐和垂直对齐 lindexi 2019-03-08 10:45:40 +0800 2 ...