Created
February 1, 2013 22:14
-
-
Save ashic/4694526 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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