static void Main(string[] args) { TcpClient client = new TcpClient(); var tsk = client.ConnectAsync(new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 }), 1984); tsk.Wait(); PikeMQ.Core.AsyncSocket socket = new Core.AsyncSocket(client.Client); var theClient = new PikeMQ.Client.PikeMQClient(socket); theClient.OnMessageReceived += (x, y) => System.Console.WriteLine("Received event in channel " + x + ", data: " + System.Text.Encoding.UTF8.GetString(y)); theClient.Run(); theClient.Connect(); theClient.SendSubscribeRequest("SomeChannel"); theClient.PostMessage("AnotherChannel", new byte[] { 0xAA, 0xFF }, Core.QoS.BestEffort); Console.WriteLine("Press key to stop"); Console.ReadLine(); while (true) { Console.WriteLine("#"); var task = theClient.PostMessage("AnotherChannel", new byte[] { 0xBB, 0xCC }, Core.QoS.BestEffort); task.RunSynchronously(); System.Threading.Thread.Sleep(50); } }
public async void Start() { listener.Start(16); while (!term) { var con = listener.AcceptSocketAsync(); await con; var client = con.Result; // we have a client, dispatch it into a remote peer and // register the peer with the master dispatcher. var asyncSock = new Core.AsyncSocket(client); RemotePeer peer = new RemotePeer(asyncSock); peerManager.RegisterPeer(peer); peer.Run(); } }