コード例 #1
0
        static public void onOpenAction(WebSocket ws, StompMessageSerializer serializer)
        {
            Console.WriteLine("Server says : open");
            var connect = new StompMessage("CONNECT");

            connect["accept-version"] = "1.1";
            connect["heart-beat"]     = "10000,10000";
            ws.Send(serializer.Serialize(connect));
        }
コード例 #2
0
        public string Serialize(StompMessage message)
        {
            var buffer = new StringBuilder();

            buffer.Append(message.Command + "\n");
            if (message.Headers != null)
            {
                foreach (var header in message.Headers)
                {
                    buffer.Append(header.Key + ":" + header.Value + "\n");
                }
            }
            buffer.Append("\n");
            buffer.Append(message.Body);
            buffer.Append('\0');
            return(buffer.ToString());
        }
コード例 #3
0
        static public void onMessageAction(WebSocket ws, StompMessageSerializer serializer, string data, int clientId)
        {
            StompMessage msg = serializer.Deserialize(data);

            if (msg.Command == StompCommand.CONNECTED)
            {
                var sub = new StompMessage("SUBSCRIBE");
                sub["id"]          = "sub-" + clientId;
                sub["destination"] = "/topic/" + clientId;
                ws.Send(serializer.Serialize(sub));
            }
            else if (msg.Command == StompCommand.MESSAGE)
            {
                JObject jObj = JObject.Parse(msg.Body);
                string  rMsg = (string)jObj["msg"];
                Console.WriteLine(rMsg);
            }
        }