Socket connects then instantly closes

Jan 18, 2012 at 5:26 PM

My example of websockets seems to have stopped working and I can't figure out why, can anyone help?

From the logs it looks like I can connect but then it instantly closes again, I've tested other people's examples and they seem fine so I doubt its a browser issue.

When I try and make the connection in Javascript:

var _socketURL = "ws://127.0.0.1:2011/sample" ;
ws = new WebSocket(_socketURL, "basic");

It instantly calls the ws.onclose function.

Here are some of my logs:

System.net.trace.log

System.Net.Sockets Verbose: 0 : [0744] Socket#62476613::Socket(InterNetwork#2)
System.Net.Sockets Verbose: 0 : [0744] Exiting Socket#62476613::Socket()
System.Net.Sockets Verbose: 0 : [0744] Socket#62476613::Bind(0:2011#2011)
System.Net.Sockets Verbose: 0 : [0744] Exiting Socket#62476613::Bind()
System.Net.Sockets Verbose: 0 : [0744] Socket#62476613::Listen(100#100)
System.Net.Sockets Verbose: 0 : [0744] Exiting Socket#62476613::Listen()
System.Net.Sockets Verbose: 0 : [0744] Socket#62476613::Accept()
System.Net.Sockets Verbose: 0 : [0744] Socket#11404313::Socket()
System.Net.Sockets Verbose: 0 : [0744] Exiting Socket#11404313::Socket()
System.Net.Sockets Verbose: 0 : [0744] Exiting Socket#62476613::Accept()     -> Socket#11404313
System.Net.Sockets Verbose: 0 : [0744] Socket#62476613::Accept()
System.Net.Sockets Verbose: 0 : [5856] Socket#11404313::Receive()
System.Net.Sockets Verbose: 0 : [5856] Data from Socket#11404313::Receive
System.Net.Sockets Verbose: 0 : [5856] 00000000 : 47 45 54 20 2F 73 61 6D-70 6C 65 20 48 54 54 50 : GET /sample HTTP
System.Net.Sockets Verbose: 0 : [5856] 00000010 : 2F 31 2E 31 0D 0A 55 70-67 72 61 64 65 3A 20 77 : /1.1..Upgrade: w
System.Net.Sockets Verbose: 0 : [5856] 00000020 : 65 62 73 6F 63 6B 65 74-0D 0A 43 6F 6E 6E 65 63 : ebsocket..Connec
System.Net.Sockets Verbose: 0 : [5856] 00000030 : 74 69 6F 6E 3A 20 55 70-67 72 61 64 65 0D 0A 48 : tion: Upgrade..H
System.Net.Sockets Verbose: 0 : [5856] 00000040 : 6F 73 74 3A 20 61 6D 64-6F 6E 6E 65 6C 6C 79 3A : ost: localhost:
System.Net.Sockets Verbose: 0 : [5856] 00000050 : 32 30 31 31 0D 0A 4F 72-69 67 69 6E 3A 20 68 74 : 2011..Origin: ht
System.Net.Sockets Verbose: 0 : [5856] 00000060 : 74 70 3A 2F 2F 61 6D 64-6F 6E 6E 65 6C 6C 79 0D : tp://localhost.
System.Net.Sockets Verbose: 0 : [5856] 00000070 : 0A 53 65 63 2D 57 65 62-53 6F 63 6B 65 74 2D 50 : .Sec-WebSocket-P
System.Net.Sockets Verbose: 0 : [5856] 00000080 : 72 6F 74 6F 63 6F 6C 3A-20 62 61 73 69 63 0D 0A : rotocol: basic..
System.Net.Sockets Verbose: 0 : [5856] 00000090 : 53 65 63 2D 57 65 62 53-6F 63 6B 65 74 2D 4B 65 : Sec-WebSocket-Ke
System.Net.Sockets Verbose: 0 : [5856] 000000A0 : 79 3A 20 34 64 75 54 66-6E 50 6F 6B 2B 6A 47 61 : y: 4duTfnPok+jGa
System.Net.Sockets Verbose: 0 : [5856] 000000B0 : 4D 36 4F 55 34 65 56 70-51 3D 3D 0D 0A 53 65 63 : M6OU4eVpQ==..Sec
System.Net.Sockets Verbose: 0 : [5856] 000000C0 : 2D 57 65 62 53 6F 63 6B-65 74 2D 56 65 72 73 69 : -WebSocket-Versi
System.Net.Sockets Verbose: 0 : [5856] 000000D0 : 6F 6E 3A 20 31 33 0D 0A-43 6F 6F 6B 69 65 3A 20 : on: 13..Cookie:
System.Net.Sockets Verbose: 0 : [5856] 000000E0 : 41 53 50 2E 4E 45 54 5F-53 65 73 73 69 6F 6E 49 : ASP.NET_SessionI
System.Net.Sockets Verbose: 0 : [5856] 000000F0 : 64 3D 7A 61 6E 6E 7A 70-34 35 35 33 61 63 62 6A : d=zannzp4553acbj
System.Net.Sockets Verbose: 0 : [5856] 00000100 : 76 35 71 6D 74 6A 66 70-35 35 0D 0A 0D 0A       : v5qmtjfp55....
System.Net.Sockets Verbose: 0 : [5856] Exiting Socket#11404313::Receive()     -> 270#270
System.Net.Sockets Verbose: 0 : [5856] Socket#11404313::Send()
System.Net.Sockets Verbose: 0 : [5856] Data from Socket#11404313::Send
System.Net.Sockets Verbose: 0 : [5856] 00000000 : 48 54 54 50 2F 31 2E 31-20 31 30 31 20 57 65 62 : HTTP/1.1 101 Web
System.Net.Sockets Verbose: 0 : [5856] 00000010 : 20 53 6F 63 6B 65 74 20-50 72 6F 74 6F 63 6F 6C :  Socket Protocol
System.Net.Sockets Verbose: 0 : [5856] 00000020 : 20 48 61 6E 64 73 68 61-6B 65 0D 0A 55 70 67 72 :  Handshake..Upgr
System.Net.Sockets Verbose: 0 : [5856] 00000030 : 61 64 65 3A 20 57 65 62-53 6F 63 6B 65 74 0D 0A : ade: WebSocket..
System.Net.Sockets Verbose: 0 : [5856] 00000040 : 43 6F 6E 6E 65 63 74 69-6F 6E 3A 20 55 70 67 72 : Connection: Upgr
System.Net.Sockets Verbose: 0 : [5856] 00000050 : 61 64 65 0D 0A 57 65 62-53 6F 63 6B 65 74 2D 4F : ade..WebSocket-O
System.Net.Sockets Verbose: 0 : [5856] 00000060 : 72 69 67 69 6E 3A 20 68-74 74 70 3A 2F 2F 61 6D : rigin: http://am
System.Net.Sockets Verbose: 0 : [5856] 00000070 : 64 6F 6E 6E 65 6C 6C 79-0D 0A 57 65 62 53 6F 63 : donnelly..WebSoc
System.Net.Sockets Verbose: 0 : [5856] 00000080 : 6B 65 74 2D 4C 6F 63 61-74 69 6F 6E 3A 20 77 73 : ket-Location: ws
System.Net.Sockets Verbose: 0 : [5856] 00000090 : 3A 2F 2F 61 6D 64 6F 6E-6E 65 6C 6C 79 3A 32 30 : ://localhost:20
System.Net.Sockets Verbose: 0 : [5856] 000000A0 : 31 31 2F 73 61 6D 70 6C-65 0D 0A 0D 0A          : 11/sample....
System.Net.Sockets Verbose: 0 : [5856] Exiting Socket#11404313::Send()     -> 173#173
System.Net.Sockets Verbose: 0 : [6436] Socket#11404313::Send()
System.Net.Sockets Verbose: 0 : [6436] Data from Socket#11404313::Send
System.Net.Sockets Verbose: 0 : [6436] 00000000 : 00                                              : .
System.Net.Sockets Verbose: 0 : [6436] Exiting Socket#11404313::Send()     -> 1#1
System.Net.Sockets Verbose: 0 : [6436] Socket#11404313::Send()
System.Net.Sockets Error: 0 : [6436] Exception in the Socket#11404313::Send - An established connection was aborted by the software in your host machine
System.Net.Sockets Verbose: 0 : [6436] Exiting Socket#11404313::Send()     -> 0#0
System.Net.Sockets Verbose: 0 : [6436] Socket#11404313::Shutdown(Both#2)
System.Net.Sockets Verbose: 0 : [6436] Exiting Socket#11404313::Shutdown()
System.Net.Sockets Verbose: 0 : [6436] Socket#11404313::Close()
System.Net.Sockets Verbose: 0 : [6436] Socket#11404313::Dispose()
System.Net.Sockets Verbose: 0 : [6436] Exiting Socket#11404313::Close()
System.Net.Sockets Verbose: 0 : [6436] Socket#11404313::Send()
System.Net.Sockets Verbose: 0 : [5856] Socket#11404313::Receive()

err.log

2012-01-18 17:12:45,597 [8] ERROR SuperWebSocket - Session:7442b32f-e4a0-421c-a591-b07f5927c9b6-7442b32f-e4a0-421c-a591-b07f5927c9b6-127.0.0.1:10632
System.IO.IOException: Unable to write data to the transport connection: Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.. ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
   at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, SocketError& errorCode)
   at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at SuperSocket.SocketEngine.SyncSocketSession`2.SendResponse(SocketContext context, Byte[] data)

info.log

2012-01-18 17:12:42,394 [1] INFO  SuperSocket - SuperWebSocket has been started
2012-01-18 17:12:45,509 [9] INFO  SuperWebSocket - Session:7442b32f-e4a0-421c-a591-b07f5927c9b6-7442b32f-e4a0-421c-a591-b07f5927c9b6-127.0.0.1:10632
New SocketSession was accepted!
2012-01-18 17:12:45,596 [8] INFO  SuperWebSocket - Session:7442b32f-e4a0-421c-a591-b07f5927c9b6-7442b32f-e4a0-421c-a591-b07f5927c9b6-127.0.0.1:10632
This session was closed!
2012-01-18 17:13:40,557 [5] INFO  SuperSocket - SuperWebSocket has been stopped

 

Any help would be appreciated.

Coordinator
Jan 20, 2012 at 5:08 AM

Which browser are you using? It seems the browser closed the connection.

And which version of the source code are you using? The handshake response from server side didn't contain accept key.