C++
,
C#
Python
. 我想让
Request-Reply
连接Android设备和运行中的PC的模式
UWP
具有
Xamarin forms
下面是
Requestor
代码:
public void HelloWorld()
{
var timer = new Timer(60000);
timer.Start();
timer.Elapsed += (sender, args) =>
{
this.Cancel = true;
timer.Stop();
};
// Create
const string endpoint = "tcp://PC_ip:3245";
using (var request = new RequestSocket())
{
request.Bind(endpoint);
Thread.Sleep(2000);
while (!Cancel)
{
request.SendFrame("Requester says hello");
var reply = request.ReceiveFrameString();
Debug.WriteLine("Gets reply {0}",reply);
}
}
}
应答套接字代码:
public void HelloWorld()
{
var timer = new Timer(60000);
const string endpoint = "tcp://PC_ip:3245";
timer.Start();
timer.Elapsed += (sender, args) =>
{
timer.Stop();
Cancel = true;
};
using (var replierSocket = new ResponseSocket())
{
replierSocket.Connect(endpoint);
Thread.Sleep(2000);
while (!Cancel)
{
var replyFromRequester = replierSocket.ReceiveFrameString();
Debug.WriteLine("Got reply {0}", replyFromRequester);
replierSocket.SendFrame("Response socket say hello");
}
}
}
Cancel
我浏览了一些贴在上面的问题,添加了延迟,这些连接代码块只有在点击应用程序上的按钮后才会触发。
调试时,
request.ReceiveFrameString()
replierSocket.ReceiveFrameString();
都没有被击中。
PC_ip代表我从ipconfig获得的IPv4地址/all代表我的wifi。我还尝试了我的机器的外部ip,比如
whatsmyip.org
在
ResponseSocket
请让我知道我做错了什么。
发布复制存储库:
GitHub/me/XamZeroMq