private static async Task <WebSocketConnectionSummary> RunReceiveTest(Func <IWritableChannel, CancellationToken, Task> producer)
        {
            using (var factory = new ChannelFactory())
            {
                var outbound = factory.CreateChannel();
                var inbound  = factory.CreateChannel();

                var timeoutToken = TestUtil.CreateTimeoutToken();

                var producerTask = Task.Run(async() =>
                {
                    await producer(inbound, timeoutToken).OrTimeout();
                    inbound.CompleteWriter();
                }, timeoutToken);

                var consumerTask = Task.Run(async() =>
                {
                    var connection = new WebSocketConnection(inbound, outbound, options: new WebSocketOptions().WithAllFramesPassedThrough());
                    using (timeoutToken.Register(() => connection.Dispose()))
                        using (connection)
                        {
                            // Receive frames until we're closed
                            return(await connection.ExecuteAndCaptureFramesAsync().OrTimeout());
                        }
                }, timeoutToken);

                await Task.WhenAll(producerTask, consumerTask);

                return(consumerTask.Result);
            }
        }
예제 #2
0
 /// <summary>
 /// Disposes the connection and stops the gesture server.
 /// </summary>
 public void Stop()
 {
     if (connection != null)
     {
         connection.Dispose();
     }
     server.Stop();
 }
예제 #3
0
 private void DisposeInternal()
 {
     try
     {
         SendDataInternal(new Dictionary <string, object> {
             { "type", "shutdown" }
         });
         Thread.Sleep(1000);
         connection.Dispose();
     }
     catch { }
 }
예제 #4
0
 public void Dispose() => _webSocket.Dispose();
예제 #5
0
 public void Dispose()
 {
     WebSocketConnection?.Dispose();
     NewMessageEvent?.Dispose();
 }