Пример #1
0
        void Open(string url)
        {
            webSocket2 = new PepperSharp.WebSocket(this);

            webSocket2.Connection  += HandleConnection;
            webSocket2.Closed      += HandleClosed;
            webSocket2.ReceiveData += HandleReceiveData;

            PostMessage("connecting...");

            try
            {
                webSocket2.Connect(url);
            }
            catch (Exception exc)
            {
                PostMessage($"connection failed {exc.Message}");
            }
        }
Пример #2
0
        async Task OpenAsync(string url)
        {
            webSocket2             = new PepperSharp.WebSocket(this);
            webSocket2.MessageLoop = messageLoop;

            PostMessage("connecting using async...");
            webSocket2.ReceiveData += HandleReceiveData;
            try
            {
                await webSocket2.ConnectAsync(new Uri(url), null);

                if (webSocket2.State != WebSocketState.Open)
                {
                    PostMessage("connection failed");
                    return;
                }
                PostMessage("connected");
                ReceiveAsync();
            }
            catch (Exception exc)
            {
                PostMessage($"connection failed {exc.Message}");
            }
        }