The client and server couldn't connect when I use WebSocket under windows8 9200.

638 views
Skip to first unread message

王利

unread,
Jul 17, 2014, 7:33:56 AM7/17/14
to golan...@googlegroups.com
client and server's codes keep same with https://github.com/astaxie/build-web-application-with-golang/blob/master/ebook/08.2.md ,I open the client with Chrome, server with CMD, and the console said:

onload 
index
.html:10 WebSocket connection to 'ws://localhost:1234/' failed: Error during WebSocket handshake: Unexpected response code: 403 
index
.html:12 connection closed (1006) 
index
.html:19 WebSocket is already in CLOSING or CLOSED state.  
No message at server-end.

<F12>-Network-Header:
  1. Request URL:
    ws://localhost:1234/
  2. Request Headers CAUTION: Provisional headers are shown.
    1. Cache-Control:
      no-cache
    2. Connection:
      Upgrade
    3. Host:
      localhost:1234
    4. Origin:
      null
    5. Pragma:
      no-cache
    6. Sec-WebSocket-Extensions:
      permessage-deflate; client_max_window_bits, x-webkit-deflate-frame
    7. Sec-WebSocket-Key:
      jE5tbcaUK+vcLJ9rjdr1Fw==
    8. Sec-WebSocket-Version:
      13
    9. Upgrade:
      websocket
    10. User-Agent:
      Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36

chrome://net-internals/#events:
7969: SOCKET
ws
://localhost:1234/
Start Time: 2014-07-17 13:58:20.672

t
=2491386 [st= 0] +SOCKET_ALIVE [dt=12]
 
 --> source_dependency = 7965 (SOCKET_STREAM)
t
=2491386 [st= 0] +TCP_CONNECT [dt=1]
 
--> address_list = ["[::1]:1234","127.0.0.1:1234"]
t
=2491386 [st= 0] TCP_CONNECT_ATTEMPT [dt=1]
 
--> address = "[::1]:1234"
t
=2491387 [st= 1] -TCP_CONNECT
 
--> source_address = "[::1]:51589"
t
=2491389 [st= 3] SOCKET_BYTES_SENT
 
--> byte_count = 420
t
=2491398 [st=12] SOCKET_BYTES_RECEIVED
 
--> byte_count = 26
t
=2491398 [st=12] -SOCKET_ALIVE

I don't know how to dea with it. It just couldn't run the same result with the github's. Thx for your help!

Dave Cheney

unread,
Jul 19, 2014, 11:58:21 PM7/19/14
to golan...@googlegroups.com
Change the server code to print out the error value, rather than just printing the fact there was an error. That should get you a little further.

Jeffrey Smith

unread,
Jul 20, 2014, 7:06:50 AM7/20/14
to golan...@googlegroups.com
The Origin header is not set which will probably throw a 403.

You will have to set this where ever you are serving up the html page from.


Reply all
Reply to author
Forward
0 new messages