Skip to content

Instantly share code, notes, and snippets.

@ashic
Created February 1, 2013 22:14
Show Gist options
  • Save ashic/4694526 to your computer and use it in GitHub Desktop.
Save ashic/4694526 to your computer and use it in GitHub Desktop.
public class ReqRepExample : Example
{
Context _context;
public void Start(Context context)
{
_context = context;
Task.Factory.StartNew(startServer);
Task.Factory.StartNew(()=> startClient("1"));
}
void startClient(string id)
{
int count = 0;
var sender = _context.Socket(SocketType.REQ);
sender.Bind(@"tcp://127.0.0.1:5555");
while (true)
{
Thread.Sleep(100);
sender.Send(string.Format("Message {0}, sender {1}", count++, id), Encoding.Unicode);
sender.Recv();
}
}
void startServer()
{
var receiver = _context.Socket(SocketType.REP);
receiver.Connect(@"tcp://127.0.0.1:5555");
while (true)
{
string reply = receiver.Recv(Encoding.Unicode);
Console.WriteLine("Received {0}", reply);
receiver.Send(new byte[0]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment