I took one of the simple receive/request socket example on https://netmq.readthedocs.io/ and wanted to make it work with a parametrizedThread in an infinite loop. The code works fine for few loops, after which it throws the
A non-blocking socket operation could not be completed immediately
For what I got the above should happen immediately after the first loop and not randomly. What is the issue here? It sounds like something has to be flushed out in order to get a clean connection again (not sure).
class Program
{
public class Connector
{
public String connection { get; set; }
public ResponseSocket server { get; set; }
public Connector(string address, ResponseSocket server_)
{
this.connection = address;
this.server = server_;
}
}
static void Main(string[] args)
{
string connection = "tcp://localhost:5555";
using (var server = new ResponseSocket())
{
while (true)
{
try
{
server.Bind(connection);
}
catch (NetMQException e)
{
Console.WriteLine(e.ErrorCode);
}
Connector c = new Connector(connection, server);
ParameterizedThreadStart parametrizedClientThread = new ParameterizedThreadStart(runClientSide);
Thread t = new Thread(parametrizedClientThread);
t.Start(c);
//runClientSide(connection, server);
}
}
}
private static void runClientSide(object param)
{
Connector conn = (Connector)param;
string connection = conn.connection;
ResponseSocket server = conn.server;
using (var client = new RequestSocket())
{
client.Connect(connection);
client.SendFrame("Hello");
string fromClientMessage = server.ReceiveFrameString();
Console.WriteLine("From Client: {0}", fromClientMessage);
server.SendFrame("Hi Back");
string fromServerMessage = client.ReceiveFrameString();
Console.WriteLine("From Server: {0}", fromServerMessage);
//Console.ReadLine();
}
}