workerman 搭桥连接3389,类似teamview

整个架构如下
share_____bridge____________________server ____________________view

共享端开启bridge,share, 服务器server做来回转发, 远程桌面连接view 使用mstsc.exe连接

share,放在共享端, share 为3389端口,不用管它 ,win7对应服务remote desktop service开启即可,
bridge,放在共享端,bridge使用workerman做pipe转发到3389

server 转发 ,接收view请求转发给bridge,接收bridge转发给view

现在问题:
mstsc.exe view,连接server后,偶尔能连上share端,大多时候,连不上!
已邀请:

wangfeishan - 看重战略,跑赢流程

赞同来自:

代码 如下
share端(bridge)
$ws_worker->onWorkerStart=function()
{
//print_r($worker);
echo "worker starting ....\n";

global $ws_worker;
global $desk_server_ip;
global $i;
//global $bridge_server;
//global $share_bridge;
global $share_bridge;

//bridge_desk_server-----------------------------------------
$share_bridge = new AsyncTcpConnection("tcp://127.0.0.1:3389");


$share_bridge->onConnect = function($share_bridge_conn)
{

$share_bridge_conn->maxSendBufferSize = 10002400;

echo "bridge 连接 3389 ok \r\n";
//service_bridge发给3389--------------------------------------
//建立连接向左侧发
$bridge_server = new AsyncTcpConnection("tcp://47.96.173.108:20000");

$bridge_server->onConnect = function($bridge_server)
{
$bridge_server->maxSendBufferSize = 10002400;

echo "bridge_server 连接 ok \r\n ";
$bridge_server->send("bridge");
};

$bridge_server->pipe($share_bridge_conn);

$share_bridge_conn->pipe($bridge_server);

$bridge_server->connect();

};


$share_bridge->connect();

};//onWorkerStart end

Worker::runAll();

wangfeishan - 看重战略,跑赢流程

赞同来自:

server端
$ws_worker->onConnect = function($connection)
{
$connection->maxSendBufferSize = 10002400;

global $i;



global $ws_worker;

$connection->onMessage = function($connection, $data)
{
$connection->maxSendBufferSize = 10002400;
global $ws_worker;
global $i;
// echo $data;
if($data!="")
{
//echo "有数据.....................\r\n";
}

//签名
//向客户端发送数据
if(!isset($connection->uid))
{
$i++;
$connection->uid="";

//如果是mstsc.exe
if(strpos($data,"msts")>-1)
{


$connection->uid="view1";


}
if(strpos($data,"bridge")>-1)
{
//bridge
$connection->uid="bridge";
}

if(strpos($data,"echo_all_client")>-1)
{
//bridge
$connection->uid="echo_all_client";

}

//echo "set uid ";
$ws_worker->uidConnections[$connection->uid]=$connection;

// echo $connection->uid." login \r\n";

}

if($connection->uid=="echo_all_client")
{



$temp="all UID :::::::::";
foreach($ws_worker->uidConnections as $connection1)
{
//所有设备接收截屏命令
$uid=$connection1->uid;

$temp=$temp. $uid." ";

}

$temp=$temp.":::::::::\r\n";
echo $temp;
///签名end
$connection->send($temp);
}


//若是view1发送信息,转发给service_bridges
if($connection->uid=="view1")
{



//echo "-----------------------view1-------------------";
//
foreach($ws_worker->uidConnections as $connection1)
{
//所有设备接收截屏命令
$uid=$connection1->uid;


//发给service_brige
if(strpos($uid,"bridge")>-1)
{
echo "收到view1, 转发给service_bridge";
$connection1->send($data);

}
}

}

//若是bridge发送信息,转发给view1
if($connection->uid=="bridge")
{
// echo "-----------------------bridge-------------------";
//
foreach($ws_worker->uidConnections as $connection1)
{

$uid=$connection1->uid;

//发给service_brige
if(strpos($uid,"view1")>-1)
{
echo "recevive bridge, to view1";
$connection1->send($data);

}
}

}





};


}; //conn结束

要回复问题请先登录注册