Пример #1
0
        static void Main(string[] args)
        {
            System.Threading.Thread.Sleep(1000);

            var uri       = new Uri("ws://localhost:8000/sample");
            var handler   = new MessageHandler();
            var etiquette = new ClientEtiquette(uri, "null", null, new Dictionary <string, string>
            {
                { "From", "Client" }
            });
            //var etiquette = new ClientEtiquette(uri, "originTest");
            var webSocketClient = new WebSocketClient(uri, etiquette, handler);

            webSocketClient.Connect();

            var messageBus = Configure.Bus
                             .UsingTransport(webSocketClient.WebSocket)
                             .Start();

            Console.WriteLine("Client started");
            Console.WriteLine("Connecting to " + uri);

            var text = string.Empty;

            while ((text = Console.ReadLine()) != "q")
            {
                var message = new Message {
                    From = "Client", Text = text
                };
                messageBus.Send(message);
            }
        }
Пример #2
0
 public WebSocketClient(Uri remoteUri,
                        ClientEtiquette etiquette,
                        IWebSocketHandler handler,
                        RemoteCertificateValidationCallback certificateValidationCallback)
     : this(remoteUri, etiquette, handler)
 {
     if (certificateValidationCallback == null)
     {
         throw new ArgumentNullException("certificateValidationCallback");
     }
     this.certificateValidationCallback = certificateValidationCallback;
 }
Пример #3
0
        public WebSocketClient(Uri uri, ClientEtiquette etiquette, IWebSocketHandler handler)
            : this(uri, etiquette)
        {
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            webSocket.Connected    = handler.Connected;
            webSocket.Received     = handler.Received;
            webSocket.Disconnected = sender => handler.Disconnected(uri.ToString());
        }
Пример #4
0
        public WebSocketClient(Uri remoteUri, ClientEtiquette etiquette)
        {
            if (remoteUri == null)
            {
                throw new ArgumentNullException("remoteUri");
            }
            if (etiquette == null)
            {
                throw new ArgumentNullException("etiquette");
            }
            if (!remoteUri.Scheme.Equals(UriWeb.UriSchemeWs) &&
                !remoteUri.Scheme.Equals(UriWeb.UriSchemeWss))
            {
                throw new ArgumentException(string.Concat(UnsupportedSchemeExceptionMessage, remoteUri.Scheme));
            }

            this.uri       = remoteUri;
            this.etiquette = etiquette;
            webSocket      = new WebSocket();
        }