websocket problems

820 views
Skip to first unread message

Vasiliy Tolstov

unread,
Sep 6, 2013, 2:08:43 AM9/6/13
to golan...@googlegroups.com
Hello. I'm try to use websocket golang package and have one issue.
I'm try to connect to my websocket server with noVNC

noVNC csends to server:

GET /websockify HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: 127.0.0.2:8080
Origin: http://127.0.0.2:8080
Sec-WebSocket-Protocol: binary, base64
Pragma: no-cache
Cache-Control: no-cache
Sec-WebSocket-Key: ZGGkl8GQgY5iJwqcaNT9GQ==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: x-webkit-deflate-frame
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,
like Gecko) Ubuntu Chromium/28.0.1500.71 Chrome/28.0.1500.71
Safari/537.36
Cookie: SessionCookie=BOqahwNlZcJyL3s2AQ7AJSJXc7B1RXf2000;
Username=mighost; lastNav=RMCNTRL_LEFTNAV;
lastHiLit=STR_TOPNAV_REMOTE_CONTROL; lItem=0; test=1; langSetFlag=0;
language=English; SID=kzprxvondltuonqq; mainpage=system;
subpage=sys_info


But server returns statuscode 400.
Server code:

func ws(c *websocket.Conn) {
io.Copy(c, c)
}


func main() {
if wsConfig, err :=
websocket.NewConfig("ws://127.0.0.2:8080/", "http://127.0.0.2:8080");
err != nil {
log.Fatalf(err.Error())
} else {
wsConfig.Protocol = []string{"binary", "base64"}
http.Handle("/websockify",
websocket.Server{Handler: ws, Config: *wsConfig})
http.Handle("/novnc/",
http.StripPrefix("/novnc/", http.FileServer(http.Dir("../novnc/"))))
err = http.ListenAndServe("127.0.0.2:8080", nil)
if err != nil {
log.Fatalf(err.Error())
}
}
}

--
Vasiliy Tolstov,
e-mail: v.to...@selfip.ru
jabber: va...@selfip.ru

Fumitoshi Ukai (鵜飼文敏)

unread,
Sep 6, 2013, 10:17:20 AM9/6/13
to Vasiliy Tolstov, golang-nuts
I think server should choose one protocol in Server.Handshake.
your Server.Handshake could set wsConfig.Protocol to []string{"binary"} or []string{"base64"}.


2013/9/6 Vasiliy Tolstov <v.to...@selfip.ru>
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Vasiliy Tolstov

unread,
Sep 7, 2013, 10:04:31 AM9/7/13
to Fumitoshi Ukai (鵜飼文敏), golang-nuts
2013/9/6 Fumitoshi Ukai (鵜飼文敏) <uk...@google.com>:
> I think server should choose one protocol in Server.Handshake.
> your Server.Handshake could set wsConfig.Protocol to []string{"binary"} or
> []string{"base64"}.


Is that possible to support two protocols in same time?

Fumitoshi Ukai (鵜飼文敏)

unread,
Sep 9, 2013, 4:54:58 AM9/9/13
to Vasiliy Tolstov, golang-nuts


On Sep 7, 2013 11:04 PM, "Vasiliy Tolstov" <v.to...@selfip.ru> wrote:
>
> 2013/9/6 Fumitoshi Ukai (鵜飼文敏) <uk...@google.com>:
> > I think server should choose one protocol in Server.Handshake.
> > your Server.Handshake could set wsConfig.Protocol to []string{"binary"} or
> > []string{"base64"}.
>
>
> Is that possible to support two protocols in same time?

what do you mean?

websocket client/server may support several protocols but a websocket connection uses one protocol (client requests a list of protocol, server choose one from the list in opening handshake).

http://tools.ietf.org/html/rfc6455

   The |Sec-WebSocket-Protocol| request-header field can be
   used to indicate what subprotocols (application-level protocols
   layered over the WebSocket Protocol) are acceptable to the client.
   The server selects one or none of the acceptable protocols and echoes
   that value in its handshake to indicate that it has selected that
   protocol.

ukai

Vasiliy Tolstov

unread,
Sep 12, 2013, 3:05:55 AM9/12/13
to Fumitoshi Ukai (鵜飼文敏), golang-nuts
2013/9/9 Fumitoshi Ukai (鵜飼文敏) <uk...@google.com>:
> what do you mean?
>
> websocket client/server may support several protocols but a websocket
> connection uses one protocol (client requests a list of protocol, server
> choose one from the list in opening handshake).
>
> http://tools.ietf.org/html/rfc6455
>
> The |Sec-WebSocket-Protocol| request-header field can be
> used to indicate what subprotocols (application-level protocols
> layered over the WebSocket Protocol) are acceptable to the client.
> The server selects one or none of the acceptable protocols and echoes
> that value in its handshake to indicate that it has selected that
> protocol.


Thanks. Sorry for delay.
I'm try to proxy novnc connection to real vnc server. Code is very
simple, but my websocket handler not run.
I'm patch server.go to printf error message and i get when connect to
my server via novnc this message in console
missing or bad WebSocket-Protocol

Client sends:
0000 47 45 54 20 2f 77 65 62 73 6f 63 6b 69 66 79 20 GET /websockify
0010 48 54 54 50 2f 31 2e 31 0d 0a 55 70 67 72 61 64 HTTP/1.1..Upgrad
0020 65 3a 20 77 65 62 73 6f 63 6b 65 74 0d 0a 43 6f e: websocket..Co
0030 6e 6e 65 63 74 69 6f 6e 3a 20 55 70 67 72 61 64 nnection: Upgrad
0040 65 0d 0a 48 6f 73 74 3a 20 31 32 37 2e 30 2e 30 e..Host: 127.0.0
0050 2e 31 3a 36 30 38 30 0d 0a 4f 72 69 67 69 6e 3a .1:6080..Origin:
0060 20 68 74 74 70 3a 2f 2f 31 32 37 2e 30 2e 30 2e http://127.0.0.
0070 31 3a 36 30 38 30 0d 0a 53 65 63 2d 57 65 62 53 1:6080..Sec-WebS
0080 6f 63 6b 65 74 2d 50 72 6f 74 6f 63 6f 6c 3a 20 ocket-Protocol:
0090 62 69 6e 61 72 79 2c 20 62 61 73 65 36 34 0d 0a binary, base64..
00a0 50 72 61 67 6d 61 3a 20 6e 6f 2d 63 61 63 68 65 Pragma: no-cache
00b0 0d 0a 43 61 63 68 65 2d 43 6f 6e 74 72 6f 6c 3a ..Cache-Control:
00c0 20 6e 6f 2d 63 61 63 68 65 0d 0a 53 65 63 2d 57 no-cache..Sec-W
00d0 65 62 53 6f 63 6b 65 74 2d 4b 65 79 3a 20 70 32 ebSocket-Key: p2
00e0 4a 72 44 61 72 44 49 43 57 30 47 77 6e 39 6a 50 JrDarDICW0Gwn9jP
00f0 55 5a 7a 77 3d 3d 0d 0a 53 65 63 2d 57 65 62 53 UZzw==..Sec-WebS
0100 6f 63 6b 65 74 2d 56 65 72 73 69 6f 6e 3a 20 31 ocket-Version: 1
0110 33 0d 0a 53 65 63 2d 57 65 62 53 6f 63 6b 65 74 3..Sec-WebSocket
0120 2d 45 78 74 65 6e 73 69 6f 6e 73 3a 20 78 2d 77 -Extensions: x-w
0130 65 62 6b 69 74 2d 64 65 66 6c 61 74 65 2d 66 72 ebkit-deflate-fr
0140 61 6d 65 0d 0a 55 73 65 72 2d 41 67 65 6e 74 3a ame..User-Agent:
0150 20 4d 6f 7a 69 6c 6c 61 2f 35 2e 30 20 28 58 31 Mozilla/5.0 (X1
0160 31 3b 20 4c 69 6e 75 78 20 78 38 36 5f 36 34 29 1; Linux x86_64)
0170 20 41 70 70 6c 65 57 65 62 4b 69 74 2f 35 33 37 AppleWebKit/537
0180 2e 33 36 20 28 4b 48 54 4d 4c 2c 20 6c 69 6b 65 .36 (KHTML, like
0190 20 47 65 63 6b 6f 29 20 55 62 75 6e 74 75 20 43 Gecko) Ubuntu C
01a0 68 72 6f 6d 69 75 6d 2f 32 38 2e 30 2e 31 35 30 hromium/28.0.150
01b0 30 2e 37 31 20 43 68 72 6f 6d 65 2f 32 38 2e 30 0.71 Chrome/28.0
01c0 2e 31 35 30 30 2e 37 31 20 53 61 66 61 72 69 2f .1500.71 Safari/
01d0 35 33 37 2e 33 36 0d 0a 43 6f 6f 6b 69 65 3a 20 537.36..Cookie:
01e0 53 65 73 73 69 6f 6e 43 6f 6f 6b 69 65 3d 52 71 SessionCookie=Rq
01f0 6a 57 52 77 49 56 6f 68 34 4c 63 79 79 77 50 54 jWRwIVoh4LcyywPT
0200 41 56 63 63 46 5a 34 36 78 6e 6c 59 78 4b 30 30 AVccFZ46xnlYxK00
0210 30 3b 20 55 73 65 72 6e 61 6d 65 3d 6d 69 67 68 0; Username=migh
0220 6f 73 74 3b 20 6c 61 73 74 4e 61 76 3d 53 59 53 ost; lastNav=SYS
0230 49 4e 46 4f 5f 4c 45 46 54 4e 41 56 3b 20 6c 61 INFO_LEFTNAV; la
0240 73 74 48 69 4c 69 74 3d 53 54 52 5f 54 4f 50 4e stHiLit=STR_TOPN
0250 41 56 5f 53 59 53 54 45 4d 5f 49 4e 46 4f 52 4d AV_SYSTEM_INFORM
0260 41 54 49 4f 4e 3b 20 6c 49 74 65 6d 3d 30 3b 20 ATION; lItem=0;
0270 74 65 73 74 3d 31 0d 0a 0d 0a test=1....

Fumitoshi Ukai (鵜飼文敏)

unread,
Sep 12, 2013, 3:11:24 AM9/12/13
to Vasiliy Tolstov, golang-nuts



2013/9/12 Vasiliy Tolstov <v.to...@selfip.ru>

2013/9/9 Fumitoshi Ukai (鵜飼文敏) <uk...@google.com>:
> what do you mean?
>
> websocket client/server may support several protocols but a websocket
> connection uses one protocol (client requests a list of protocol, server
> choose one from the list in opening handshake).
>
> http://tools.ietf.org/html/rfc6455
>
>    The |Sec-WebSocket-Protocol| request-header field can be
>    used to indicate what subprotocols (application-level protocols
>    layered over the WebSocket Protocol) are acceptable to the client.
>    The server selects one or none of the acceptable protocols and echoes
>    that value in its handshake to indicate that it has selected that
>    protocol.


Thanks. Sorry for delay.
I'm try to proxy novnc connection to real vnc server. Code is very
simple, but my websocket handler not run.
I'm patch server.go to printf error message and i get when connect to
my server via novnc this message in console
missing or bad WebSocket-Protocol

How about your Server.Handshake code?
Did you set one protocol in Config.Protocol?

Vasiliy Tolstov

unread,
Sep 12, 2013, 3:25:16 AM9/12/13
to Fumitoshi Ukai (鵜飼文敏), golang-nuts
2013/9/12 Fumitoshi Ukai (鵜飼文敏) <uk...@google.com>:
> How about your Server.Handshake code?
> Did you set one protocol in Config.Protocol?


http://play.golang.org/p/Uv7ayYu1XA

Fumitoshi Ukai (鵜飼文敏)

unread,
Sep 12, 2013, 3:30:04 AM9/12/13
to Vasiliy Tolstov, golang-nuts
I think you need to do something like this (not tested)


2013/9/12 Vasiliy Tolstov <v.to...@selfip.ru>

Vasiliy Tolstov

unread,
Sep 12, 2013, 3:46:16 AM9/12/13
to Fumitoshi Ukai (鵜飼文敏), golang-nuts
2013/9/12 Fumitoshi Ukai (鵜飼文敏) <uk...@google.com>:
> I think you need to do something like this (not tested)
> http://play.golang.org/p/X0pQMIa_FM


Thanks. Works fine. is that possible to add more docs to websocket
package about handshake and supported protocols?
Reply all
Reply to author
Forward
0 new messages