WebSocketListener
WebSocketListener copied to clipboard
WebSocketException: Not GET request
Hello! I have a next exception when client try to connect to listener by wss:
Api.Hubs.Private.WebSocket.WebSocketHubPrivate+<AcceptWebSocketClientAsync>c__async0: WebSocket Stop accepting clients vtortola.WebSockets.WebSocketException: Not GET request
at vtortola.WebSockets.WebSocketHandshaker.ParseGET (System.String line, vtortola.WebSockets.WebSocketHandshake handshake) [0x0001f] in <3efbcd29638a4658ba36943efbb4aba5>:0
at vtortola.WebSockets.WebSocketHandshaker.ReadHttpRequest (System.IO.Stream clientStream, vtortola.WebSockets.WebSocketHandshake handshake) [0x0001a] in <3efbcd29638a4658ba36943efbb4aba5>:0
at vtortola.WebSockets.WebSocketHandshaker+<HandshakeAsync>d__0.MoveNext () [0x00043] in <3efbcd29638a4658ba36943efbb4aba5>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <8f2c484307284b51944a1a13a14c0266>:0
at vtortola.WebSockets.WebSocketListener+<AcceptWebSocketAsync>d__4.MoveNext () [0x000be] in <3efbcd29638a4658ba36943efbb4aba5>:0
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <8f2c484307284b51944a1a13a14c0266>:0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in <8f2c484307284b51944a1a13a14c0266>:0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in <8f2c484307284b51944a1a13a14c0266>:0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in <8f2c484307284b51944a1a13a14c0266>:0
at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0
at Api.Hubs.Private.WebSocket.WebSocketHubPrivate+<AcceptWebSocketClientAsync>c__async0.MoveNext () [0x000d4] in <7cc61b8be3914d60aa0c0c7123236ba4>:0
Code for creating listener was used from examples. SSL feature enabling code:
var options = new WebSocketListenerOptions () {
NegotiationQueueCapacity = Convert.ToInt32(ConfigurationManager.AppSettings["Api.Notifications.Private.WebSocket.NegotiationQueueCapacity"]),
ParallelNegotiations = Convert.ToInt32(ConfigurationManager.AppSettings["Api.Notifications.Private.WebSocket.ParallelNegotiations"]),
SubProtocols = new [] { "text" }
};
server = new WebSocketListener (endpoint, options);
var rfc6455 = new vtortola.WebSockets.Rfc6455.WebSocketFactoryRfc6455 (server);
server.Standards.RegisterStandard (rfc6455);
var certPath = ConfigurationManager.AppSettings ["Api.Notifications.Private.WebSocket.Certificate.File"].ToString();
var certPass = ConfigurationManager.AppSettings ["Api.Notifications.Private.WebSocket.Certificate.Password"].ToString();
certificate = new X509Certificate2(certPath, certPass);
server.ConnectionExtensions.RegisterExtension (new WebSocketSecureConnectionExtension (certificate));
Thank You in advance! // alex
Hi,
Is it a self-signed certificate? Does it work when you use it with HTTPS?
Cheers.
Hello,
yes, this is a self-signed certificate. Apache httpd ssl working with this sertificate (converted to pem/key). For Web-Socket hub in the project i use pfx (p12) format and password.
// sincerely, alex
The browser needs the user to accept that certificate, are you using it for HTTPS as well in the same page that is initiating the WebSocket connection?
Yes, in opening the page browser (chrome) write about self-signed certificate ( and allow to select "Continue with this certificate..". I press it and continue to working with page. But web-socket can't connect until i open this connection (wss://....) address directly in web-browser and select again "Continue with this certificate.., and only after it and reloading page web-socket connection is established and in status 101. But in the server logs still have this exception - "Not GET Request" :( And as result - can't send notifications by web-socket chanel from server to client
// sincerely, alex
Have you tried with these approaches? https://stackoverflow.com/questions/18462064/associate-a-private-key-with-the-x509certificate2-class-in-net/24863777#24863777
Yes, i convert *.pem certificate to *.p12 using openssl unix-utility
But now i see that it's working without any problems if i use not self-signed certificate.. So it can be certificate problem. For converting normal certificate i have used same way.
It's possible if problem with certificate, WebSocketLibrary have a wrong request string? And throw this exception: https://github.com/vtortola/WebSocketListener/blob/master/vtortola.WebSockets/Http/WebSocketHandshaker.cs#L179
// sincerely, alex
fyi. I get this when my certificate expires