将 go websocket 库更新到最新版本

发布于 2025-01-07 21:33:11 字数 800 浏览 0 评论 0原文

我正在 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())
    }
}

但是,我无法连接到服务器与我的版本铬 (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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遗失的美好 2025-01-14 21:33:11

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

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

每周开发发布文档: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.

人生百味 2025-01-14 21:33:11

我猜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)

更新< /strong>:抱歉,我写/读太快了,似乎不起作用,页面显示:“不是 websocket 协议”(这里是 64b Ubuntu 上的 Chrome 18.0.1025.33 beta 10.04)

更新 2012-08-22:上面 (1) 有关编辑 websocket 包的说明不再有效。 websocket 包同时已更新,上面的示例(主要)代码现在可以编译,不会出现问题。不管怎样,我还没有测试过它之后是否做了应该做的事情,抱歉。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文