WebSocketListener icon indicating copy to clipboard operation
WebSocketListener copied to clipboard

WSS Configuration

Open AlhasanDeveloper opened this issue 7 years ago • 2 comments

Greetings,

I am trying to connect using WSS but I keep on receiving gibberish data when reading.

Here is the code for starting the server

CancellationTokenSource cancellation = new CancellationTokenSource();
var server = new WebSocketListener(new IPEndPoint(IPAddress.Loopback, Config.WSPort), config.WSOptions);
var rfc6455 = new vtortola.WebSockets.Rfc6455.WebSocketFactoryRfc6455(server);
server.Standards.RegisterStandard(rfc6455);
WebSocketSecureConnectionExtension tls = new WebSocketSecureConnectionExtension(Config.privateKeyServerAuthentication);
server.ConnectionExtensions.RegisterExtension(tls);
server.Start();

as for configuration

WSPort = 8443;
WSOptions = new vtortola.WebSockets.WebSocketListenerOptions(){
   PingTimeout = System.Threading.Timeout.InfiniteTimeSpan,
   NegotiationQueueCapacity = Environment.ProcessorCount * 128,
   ParallelNegotiations = Environment.ProcessorCount * 16,
   NegotiationTimeout = TimeSpan.FromSeconds(5),
   WebSocketSendTimeout = TimeSpan.FromSeconds(5),
   WebSocketReceiveTimeout = TimeSpan.FromSeconds(5),
   SendBufferSize = 16384,
   OnHttpNegotiation = null,
   UseNagleAlgorithm = false,
   PingMode = vtortola.WebSockets.PingModes.LatencyControl
};

as for receiving data

String msg = String.Empty;
WebSocketMessageReadStream messageReadStream = await ws.ReadMessageAsync(token);
if (messageReadStream.MessageType == WebSocketMessageType.Text)
{
   var msgContent = string.Empty;
   using (var sr = new StreamReader(messageReadStream, Encoding.UTF8))
      msgContent = sr.ReadToEnd();
      msg = msgContent;
}

There is no problem with what the server sends to the client but my problem is with receiving the data it is always gibberish, am I doing something wrong here?

Thanks.

Edit: I am new to commenting in github just highlighted codes.

AlhasanDeveloper avatar Aug 12 '18 09:08 AlhasanDeveloper

Hi,

If you try to create a server without TLS, do you receive the data correctly in the server?

vtortola avatar Aug 24 '18 22:08 vtortola

Yes, there is no problem with the data in that case.

AlhasanDeveloper avatar Aug 24 '18 22:08 AlhasanDeveloper