Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSS Configuration #133

Open
AlhasanDeveloper opened this issue Aug 12, 2018 · 2 comments
Open

WSS Configuration #133

AlhasanDeveloper opened this issue Aug 12, 2018 · 2 comments

Comments

@AlhasanDeveloper
Copy link

AlhasanDeveloper commented Aug 12, 2018

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.

@vtortola
Copy link
Owner

Hi,

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

@AlhasanDeveloper
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants