1. 程式人生 > >為什麽從服務器與客戶端不能接收消息NetMQ框架?

為什麽從服務器與客戶端不能接收消息NetMQ框架?

toc main net rec 使用 ssa oid frame 接收消息

最近,我使用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:客戶端不能接收消息! ! !

為什麽從服務器與客戶端不能接收消息NetMQ框架?