I am running the Go compiler on Ubuntu, installed using sudo apt-get install golang
I've successfully compiled and executed the code for a Trivial example server (See http://golang.org/pkg/websocket/#Handler )
package main
import (
"http"
"io"
"websocket"
)
// Echo the data received on the Web Socket.
func EchoServer(ws *websocket.Conn) {
io.Copy(ws, ws);
}
func main() {
http.Handle("/echo", websocket.Handler(EchoServer));
err := http.ListenAndServe(":12345", nil);
if err != nil {
panic("ListenAndServe: " + err.String())
}
}
However, I fail to connect to the server with my version of Chromium (16.0.912.77). I assume Chrome has implemented the RFC 6455 Websocket (version 13), but that the go websocket library in the Ubuntu golang package is out of date.
So, my question is: How can I update only the websocket package to the latest version?
The latest version of the Go websocket
package is net/websocket
at code.google.com/p/go.net/websocket
, which requires the Go 1 weekly development release.
For Ubuntu golang-weekly: Ubuntu PPA packages for Go.
For weekly development release documentation: Go Programming Language.
I guess the version of Go in Ubuntu package repository is probably r60.3 (or so), which is a bit old now. Use latest weekly, change the code to:
package main
import (
"code.google.com/p/go.net/websocket"
"io"
"net/http"
)
// Echo the data received on the Web Socket.
func EchoServer(ws *websocket.Conn) {
io.Copy(ws, ws)
}
func main() {
http.Handle("/echo", websocket.Handler(EchoServer))
err := http.ListenAndServe(":12345", nil)
if err != nil {
panic("ListenAndServe: " + err.Error())
}
}
Moreover in the websocket package s/ParseRequestURI/ParseRequest/
, then it seems to work here.(1)
Update: Sorry, I wrote/read too fast, it doesn't seem to work, the page shows: "not websocket protocol" (here is Chrome 18.0.1025.33 beta on 64b Ubuntu 10.04)
Update 2012-08-22: The above (1) note about editing the websocket package doesn't hold anymore. The websocket package has been meanwhile updated and the example (main) code above now compiles w/o problems. Anyway, I haven't tested if it afterwards does what is should or not, sorry.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With