private void button3_Click(object sender, EventArgs e)
 {
     var content = new Content() { Subject = "Stomp client", Message = "Hello World!!" };
     var broad = new StompMessage(StompFrame.SEND, JsonConvert.SerializeObject(content));
     broad["content-type"] = "application/json";
     broad["destination"] = "/app/broadcast";
     ws.Send(serializer.Serialize(broad));
 }
 private void ConnectStomp()
 {
     var connect = new StompMessage(StompFrame.CONNECT);
     connect["accept-version"] = "1.2";
     connect["host"] = "";
     // first number Zero mean client not able to send Heartbeat,
     //Second number mean Server will sending heartbeat to client instead
     connect["heart-beat"] = "0,10000";
     ws.Send(serializer.Serialize(connect));
 }
Esempio n. 3
0
        /// <summary>
        ///   Serializes the specified message.
        /// </summary>
        /// <param name = "message">The message.</param>
        /// <returns>A serialized version of the given <see cref="StompMessage"/></returns>
        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());
        }
        /// <summary>
        ///   Serializes the specified message.
        /// </summary>
        /// <param name = "message">The message.</param>
        /// <returns>A serialized version of the given <see cref="StompMessage"/></returns>
        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();
        }
        static void Main(string[] args)
        {
            using (var ws = new WebSocket("ws://localhost:8080/spring-websocket-stomp-apollo/chat/websocket"))
            {
                ws.OnMessage += ws_OnMessage;
                ws.OnOpen += ws_OnOpen;
                ws.OnError += ws_OnError;
                ws.Connect();
                Thread.Sleep(1000);

                StompMessageSerializer serializer = new StompMessageSerializer();

                var connect = new StompMessage("CONNECT");
                connect["accept-version"] = "1.2";
                connect["host"] = "";
                ws.Send(serializer.Serialize(connect));

                var clientId = RandomString(5);
                Console.WriteLine("Client Id :" + clientId);
                Thread.Sleep(1000);

                var sub = new StompMessage("SUBSCRIBE");
                sub["id"] = "sub-0";
                sub["destination"] = "/topic/broadcast";
                ws.Send(serializer.Serialize(sub));

                var sub1 = new StompMessage("SUBSCRIBE");
                sub1["id"] = "sub-1";
                sub1["destination"] = "/queue/message-" + clientId;
                ws.Send(serializer.Serialize(sub1));

                Thread.Sleep(1000);
                var content = new Content(){ Subject ="Stomp client", Message = "Hello World!!"};
                var broad = new StompMessage("SEND", JsonConvert.SerializeObject(content));
                broad["content-type"] = "application/json";
                broad["destination"] = "/app/broadcast";
                ws.Send(serializer.Serialize(broad));

                Console.ReadKey(true);
            }
        }
        private void SubscribeStomp()
        {
            var sub = new StompMessage(StompFrame.SUBSCRIBE);
            //unique Key per subscription
            sub["id"] = "sub-0";
            sub["destination"] = "/topic/broadcast";
            ws.Send(serializer.Serialize(sub));

            var sub1 = new StompMessage(StompFrame.SUBSCRIBE);
            //unique Key per subscription
            sub1["id"] = "sub-1";
            sub1["destination"] = "/queue/message-" + clientId;
            ws.Send(serializer.Serialize(sub1));
        }