更新go websocket库到最新版本

huangapple go评论92阅读模式
英文:

Updating go websocket library to latest version

问题

我正在Ubuntu上运行Go编译器,使用sudo apt-get install golang进行安装。

我已经成功编译并执行了一个“微不足道的示例服务器”代码(请参阅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())
    }
}

然而,我无法使用我的版本的Chromium(16.0.912.77)连接到服务器。我假设Chrome已经实现了RFC 6455 Websocket(版本13),但是Ubuntu的_golang_软件包中的go websocket库已经过时了。

所以,我的问题是:如何仅更新websocket包到最新版本?

英文:

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?

答案1

得分: 3

Go websocket包的最新版本是net/websocket,位于code.google.com/p/go.net/websocket,需要Go 1周开发版本。

对于Ubuntu golang-weekly:Ubuntu PPA Go软件包

对于周开发版本的文档:Go编程语言

英文:

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.

答案2

得分: 2

我猜Ubuntu软件包仓库中的Go版本可能是r60.3(或者类似的版本),现在有点过时了。使用最新的每周版本,将代码更改为:

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())
        }
}

此外,在websocket包中将s/ParseRequestURI/ParseRequest/,然后它似乎在这里工作。(1

更新:对不起,我写/读得太快了,它似乎不起作用,页面显示:“不是websocket协议”(这里是Chrome 18.0.1025.33 beta在64位Ubuntu 10.04上)

更新2012-08-22:上述(1)关于编辑websocket包的注释不再适用。websocket包已经更新,上面的示例(main)代码现在可以编译而无需任何问题。无论如何,我没有测试它是否按照预期工作,对不起。

英文:

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.

huangapple
  • 本文由 发表于 2012年2月22日 00:15:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/9380994.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定