コード例 #1
0
        public WebsocketSharpAdapter(WebSocket ws, WebsocketConfiguration config)
        {
            this.ws     = ws;
            this.config = config;

            ws.OnOpen    += OnWebsocketOpen;
            ws.OnClose   += OnWebsocketClose;
            ws.OnError   += OnWebsocketError;
            ws.OnMessage += OnWebsocketMessage;
        }
コード例 #2
0
        public IWebsocket Build(WebsocketConfiguration config)
        {
            var websocket = new WebSocket(config.uri);

            websocket.InternalRequest.ConnectTimeout = TimeSpan.FromSeconds(8);

            var adapter = new BestHTTPWebsocketAdapter(websocket);

            websocket.OnOpen    += (_) => config.onOpenCallback(adapter);
            websocket.OnClosed  += (_, code, message) => config.onCloseCallback(adapter, code, message);
            websocket.OnError   += (_, message) => config.onErrorCallback(adapter, message);
            websocket.OnMessage += (_, msg) => config.onMessageCallback(adapter, msg);

            return(adapter);
        }
コード例 #3
0
ファイル: Socket.cs プロジェクト: twoquestions/PhoenixSharp
        // params - The params to send when connecting, for example `{user_id: userToken}`
        public void Connect(string url, Dictionary <string, string> parameters = null)
        {
            if (websocket != null)
            {
                Disconnect();
            }

            var config = new WebsocketConfiguration()
            {
                uri               = BuildEndpointURL(url, parameters),
                onOpenCallback    = WebsocketOnOpen,
                onCloseCallback   = WebsocketOnClose,
                onErrorCallback   = WebsocketOnError,
                onMessageCallback = WebsocketOnMessage
            };

            websocket = websocketFactory.Build(config);

            state = State.Connecting;
            websocket.Connect();
        }
コード例 #4
0
        public void Connect()
        {
            // connectClock++;
            if (Conn != null)
            {
                return;
            }

            _closeWasClean = false;

            var config = new WebsocketConfiguration
            {
                uri               = EndPointUrl(),
                onOpenCallback    = OnConnOpen,
                onCloseCallback   = OnConnClose,
                onErrorCallback   = OnConnError,
                onMessageCallback = OnConnMessage
            };

            Conn = _websocketFactory.Build(config);

            Conn.Connect();
        }
コード例 #5
0
        public IWebsocket Build(WebsocketConfiguration config)
        {
            var socket = new WebSocket(config.uri.AbsoluteUri);

            return(new WebsocketSharpAdapter(socket, config));
        }