Esempio n. 1
0
 public void HandleMessage(ByteBuffer message, WebSocket reciever)
 {
     switch ((int)message.CurrentByte)
     {
         case 1:
             //Connect
             //Example: 1::
             //or 1::/text?my=param
             //Echo to Acknowledge
             reciever.Send(message);
             break;
         case 2:
             //Heartbeat
             //Should do timeout disconnection and removal
             //Echo to Acknowledge
             reciever.Send(message);
             break;
         case 3:
             //Message
             //Example: 3:1::blabla
             //3:[id]:[endpoint]:[data]
             Console.WriteLine(message.ToString());
             break;
         case 4:
             //JSON Message
             //Example: 4:1::{"a":"b"}
             //4:[id]:[endpoint]:[json]
             break;
         case 5:
             //Event
             //Same as JSON
             //Mandantory string name and array args
             break;
         case 6:
             //ACK
             //6:::4
             //6:::4+["A","B"]
             //Not exactly sure on this one
             break;
         case 7:
             //Error
             //7::[endpoint]:[reason]+[advice]
             break;
         case 8:
             //Noop
             break;
     }
 }
Esempio n. 2
0
 public void OnConnect(WebSocket sock)
 {
     sock.Send("1::");
     var time = AppHost.AddTimeout(new TimeSpan(0, 0, 12), new InfiniteRepeatBehavior(), null, (app, data) => { sock.Send("2::"); });
     sock.OnData += (msg) => {
         Console.WriteLine("Received Message: {0}", System.Text.Encoding.UTF8.GetString(msg.Bytes, msg.Position, msg.Length));
         HandleMessage(msg, sock);
     };
 }