Ejemplo n.º 1
0
        public Task <bool> ConnectAsync(SocketCreationContext connectionInfo)
        {
            //Before connect we need to create a callback to complete the async task
            //if the caller continues before connection was successful then we actually
            //end up in a bad state where it'll try to send before it's connected.
            TaskCompletionSource <bool> connectionResult = new TaskCompletionSource <bool>();

            //TODO: Unregister these.
            //Complete the task depending on task state
            //and the callbacks.
            this.OnOpen  += () => connectionResult.SetResult(true);
            this.OnError += msg =>
            {
                if (!connectionResult.Task.IsCompleted)
                {
                    connectionResult.SetResult(false);
                }
            };
            this.OnClose += reason =>
            {
                if (!connectionResult.Task.IsCompleted)
                {
                    connectionResult.SetResult(false);
                }
            };

            OnMessage += OnMessageRecieved;

            //It already allocated for the specific URL/URI
            Connect();

            return(connectionResult.Task);
        }
        public Task <bool> Connect(SocketCreationContext socketConnectionContext)
        {
            if (InternalSocket.State == WebSocketState.Connecting || InternalSocket.State == WebSocketState.Open)
            {
                return(Task.FromResult(true));
            }

            return(InternalSocket.ConnectAsync(socketConnectionContext));
        }
        public IRsSocket Create(SocketCreationContext context)
        {
            DefaultWebSocketClient editorWebSocketClient = new DefaultWebSocketClient($"wss://{context.Endpoint}:{context.Port}");

            editorWebSocketClient.OnError += msg => Console.WriteLine($"WebSocket Error: {msg}");
            editorWebSocketClient.OnOpen  += () => Console.WriteLine($"Opened WebSocket.");
            WebSocketRsSocketClientAdapter clientAdapter = new WebSocketRsSocketClientAdapter(editorWebSocketClient, true);

            return(clientAdapter);
        }
Ejemplo n.º 4
0
        public IRsSocket Create(SocketCreationContext context)
        {
            if (!isInitialized)
            {
                Initialize();
            }

            //WebGL from browser will use HTTPS so it required WSS
            string url        = $"wss://{context.Endpoint}:{context.Port}";
            int    instanceId = WebSocketAllocate(url);

            WebGLWebSocket socket = new WebGLWebSocket(instanceId, TaskDelayFactory);

            instances.Add(instanceId, socket);

            socket.OnOpen += () => SocketOnOpen(socket);

            //Now we make an adapter for the IRsSocket interface.
            return(new WebSocketRsSocketClientAdapter(socket, false));
        }
Ejemplo n.º 5
0
 public IRsSocket Create(SocketCreationContext context)
 {
     return(new RSSocket(RunnableStarter, openSocket(context.Endpoint, context.Port)));
 }
Ejemplo n.º 6
0
 //We were passed a TcpClient that is assumed to be connected already
 public async Task <bool> Connect(SocketCreationContext socketConnectionContext)
 {
     return(true);
 }
Ejemplo n.º 7
0
 //Default implementation is to just return, caller should connect the socket.
 public Task <bool> Connect(SocketCreationContext socketConnectionContext)
 {
     return(Task.FromResult(true));
 }
 public IRsSocket Create(SocketCreationContext context)
 {
     return(new WebGLTcpClientRsSocket(new TcpClient(context.Endpoint, context.Port)));
 }
Ejemplo n.º 9
0
        public async Task <bool> ConnectAsync(SocketCreationContext connectionInfo)
        {
            await Connect(new Uri($"wss://{connectionInfo.Endpoint}:{connectionInfo.Port}"));

            return(m_Socket.State == System.Net.WebSockets.WebSocketState.Connecting || m_Socket.State == System.Net.WebSockets.WebSocketState.Open);
        }