public static void Main (string[] args) { Console.WriteLine ("Boiler WebSocket Server"); /* * TODO implement options * OptionSet options = new OptionSet () { {"b|boiler=", "the location of {BOILER} framework", (string v) => {MainClass.args.Add("boiler", v);} } }; try { options.Parse (args); } catch (OptionException e) { Console.WriteLine (e.Message); options.WriteOptionDescriptions (Console.Out); return; } */ //TODO change to config file IPEndPoint ip = new IPEndPoint(IPAddress.Any, 8282); //TODO add TLS WAMPServer wamps = new WAMPServer (ip); //TODO change to config file IPEndPoint ep = new IPEndPoint (IPAddress.Any, 8181); Socket s = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { s.Bind(ep); s.Listen(100); } catch (Exception e) { Console.WriteLine (e.ToString ()); } //TODO very rudimentary. We should really develop a WAMP client for PHP to publish through the proper WAMP channels while (true) { Console.WriteLine ("Waiting for request..."); Socket client = s.Accept(); Console.WriteLine ("Server Request"); MemoryStream stream = new MemoryStream (); byte[] buf = new byte[1024]; int recvBytes; while ((recvBytes = client.Receive(buf)) > 0) { stream.Write (buf, 0, recvBytes); } stream.Seek (0, SeekOrigin.Begin); byte[] message = new byte[stream.Length]; stream.Read (message, 0, (int)stream.Length); JObject sentMessage = JObject.Parse(Encoding.UTF8.GetString(message)); Console.WriteLine ("Server Message: " + (string)sentMessage["channel"]); wamps.PublishEvent ((string)sentMessage ["channel"], "", new JArray (), (JObject)sentMessage ["data"]); client.Close (); } //TODO send WebSocketCloseStatus.GOING_AWAY to clients still connected }
protected virtual void OnWAMPPublish(JArray message) { string publishID = GenerateRandomID(); WAMPServer svr = (WAMPServer)this.server; //TODO should we take account of the realm? if (message.Count == 4) { svr.PublishEvent((string)message [3], publishID); } else if (message.Count == 5) { svr.PublishEvent((string)message [3], publishID, (JArray)message [4]); } else if (message.Count == 6) { svr.PublishEvent((string)message [3], publishID, (JArray)message [4], (JObject)message [5]); } Console.WriteLine("Publish request from {0}", ((IPEndPoint)this.clientSocket.RemoteEndPoint).Address.ToString()); //TODO IF NOT - Haven't we already said we've published? Spec says send "Published" first - I suggest sending after publishing to all channels. if (((JObject)message [2]) ["acknowledge"] != null) { JArray packet = new JArray(); packet.Add(WAMPMessageType.PUBLISHED); packet.Add(message [1]); packet.Add(publishID); this.Send(packet.ToString()); } }
protected virtual void OnWAMPCall(JArray message) { string invocationID = GenerateRandomID(); WAMPServer svr = (WAMPServer)this.server; //TODO should we take account of the realm? if (message.Count == 4) { svr.InvokeEvent((string)message [3], invocationID); } else if (message.Count == 5) { svr.InvokeEvent((string)message [3], invocationID, (JArray)message [4]); } else if (message.Count == 6) { svr.InvokeEvent((string)message [3], invocationID, (JArray)message [4], (JObject)message [5]); } //TODO Add errors }
public WAMPClient(WAMPServer server, Socket s) : base(server, s) { this.OnHandshakeRequest += this.ConfirmProtocol; this.OnPacketReceived += this.LaunchWAMPEvents; }
public static void Main(string[] args) { Console.WriteLine("Boiler WebSocket Server"); /* * TODO implement options * * OptionSet options = new OptionSet () { * {"b|boiler=", "the location of {BOILER} framework", (string v) => {MainClass.args.Add("boiler", v);} } * }; * * try { * options.Parse (args); * } catch (OptionException e) { * Console.WriteLine (e.Message); * options.WriteOptionDescriptions (Console.Out); * return; * } */ //TODO change to config file IPEndPoint ip = new IPEndPoint(IPAddress.Any, 8282); //TODO add TLS WAMPServer wamps = new WAMPServer(ip); //TODO change to config file IPEndPoint ep = new IPEndPoint(IPAddress.Any, 8181); Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { s.Bind(ep); s.Listen(100); } catch (Exception e) { Console.WriteLine(e.ToString()); } //TODO very rudimentary. We should really develop a WAMP client for PHP to publish through the proper WAMP channels while (true) { Console.WriteLine("Waiting for request..."); Socket client = s.Accept(); Console.WriteLine("Server Request"); MemoryStream stream = new MemoryStream(); byte[] buf = new byte[1024]; int recvBytes; while ((recvBytes = client.Receive(buf)) > 0) { stream.Write(buf, 0, recvBytes); } stream.Seek(0, SeekOrigin.Begin); byte[] message = new byte[stream.Length]; stream.Read(message, 0, (int)stream.Length); JObject sentMessage = JObject.Parse(Encoding.UTF8.GetString(message)); Console.WriteLine("Server Message: " + (string)sentMessage["channel"]); wamps.PublishEvent((string)sentMessage ["channel"], "", new JArray(), (JObject)sentMessage ["data"]); client.Close(); } //TODO send WebSocketCloseStatus.GOING_AWAY to clients still connected }