为什么从服务器与客户端不能接收消息NetMQ框架?

最近,我使用NetMQ发送或接收服务器和客户端之间的消息。 服务器密码:

void Main()
{
  CreatePullAndPushSocket();
  Task.Factory.StartNew(()=> {
        while (true)
        {
            Thread.Sleep(1);
            if (Pull != null)
            {
                var message = Pull.ReceiveFrameString();
            }
        }
    });
}
PullSocket Pull;
PushSocket Push;
private void CreatePullAndPushSocket()
{
    Pull = new PullSocket("tcp://ip1:port1");
    Push = new PushSocket("tcp://ip2:port2");
}
public void SendMessageToClient(string message)
{
    if (Push != null)
    {
        Push.SendFrame(message);
    }
}

客户端代码:

void Main()
{
new Thread(()=> {
while (true)
{
Thread.Sleep(1);
if (Pull != null)
{
var message = Pull.ReceiveFrameString();
}
}
}).Start();
}
PullSocket Pull;
PushSocket Push;
private void CreatePullAndPushSocket()
{
Pull = new PullSocket("tcp://ip2:port2");
Push = new PushSocket("tcp://ip1:port1");
}
public void SendMessageToClient(string message)
{
if (Push != null)
{
Push.SendFrame(message);
}
}
当我运行两个应用程序中,服务器应用程序,另一个是客户端应用程序。

1:客户端发送消息到服务器
2:服务器可以接收来自客户机的消息
3:服务器发送另一个消息给客户端
4:客户端不能接收消息! ! !

猜你喜欢

转载自blog.51cto.com/14021402/2320713
今日推荐