Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating go websocket library to latest version

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?

like image 966
ANisus Avatar asked Feb 21 '12 16:02

ANisus


2 Answers

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.

like image 185
peterSO Avatar answered Oct 19 '22 21:10

peterSO


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.

like image 41
zzzz Avatar answered Oct 19 '22 21:10

zzzz