I am trying to use NetMQ to send and receive messages from the Request/Response pattern. I want to simulate network disconnect by reopen the response server. The messaging sometimes fails when reopen the response server.
What am I doing wrong? Any information or assistance would be greatly appreciated.
Request Client:
RequestSocket client = new RequestSocket();
client.Connect(address);
while(true)
{
client.SendFrame(dataBytes);
client.ReceiveFrameString();
Thread.Sleep(100);
}
Also tried Request Client with Try*, and re-connect if the client does not receive any reponse for a while:
bool success = false;
while(true)
{
success = client.TrySendFrame(TimeSpan.FromMilliseconds(500), dataBytes);
if (success)
{
break;
}
Thread.Sleep(100);
}
int count = 0;
success = false;
while(true)
{
success = client.TryReceiveFrameString(TimeSpan.FromMilliseconds(500), out string s);
if (success)
{
break;
}
count++;
if (count >= 50)
{
client.Disconnect(address);
client.Connect(address);
break;
}
Thread.Sleep(100);
}
Response Server (manually close and open program again):
ResponseSocket server = new ResponseSocket(connection);
while(true)
{
if (server.TryReceiveFrameBytes(TimeSpan.FromMilliseconds(300), out byte[] dataBytes))
{
server.SendFrame("Response");
}
Thread.Sleep(100);
}