private static void Main(string[] args) { const string address = "ws://localhost:8181/"; var wsListener = new StompWebsocketListener(address); wsListener.OnConnect += stompClient => { Console.WriteLine("a new client connected!"); stompClient.OnMessage += msg => Console.Out.WriteLine("msg received: {0} {1}", msg.Command, msg.Body); }; var server = new StompServer(wsListener); server.Start(); var client = new StompClient(new WebTransportTransport(address)); client.Connect(); client.Send("/queue/test", "hi there. you are the first to connect"); Console.Out.WriteLine("Press [Enter] to stop the server"); Console.ReadLine(); }
/// <summary> /// Gets the connection. /// </summary> /// <param name = "address">The address.</param> /// <returns></returns> private StompClient GetConnection(IEndpointAddress address) { EnsureProtocolIsCorrect(address.Uri); var serverAddress = new UriBuilder("ws", address.Uri.Host, address.Uri.Port).Uri; return _connectionCache .Retrieve(address.Uri, () => { var client = new StompClient(); client.Connect(serverAddress); return client; }); }