转到Websocket服务器与Python高速公路客户端冲突

I have been successfully writing a Go (server) websocket 'chat' application based in this example code

Both client and server work as expected.

When I have come to implement a client using Python's Autobahn I am running into trouble. it is based on this example

ws://localhost:8080/ws (which works in Chrome) yields an HTTP 1.0/400 from the server. ws://localhost:8080/ (does not work in Chrome) yields an HTTP 1.0/200 from the server (in both cases).

Scanning the source (I admit, I don't know the WS protocol) seems to imply that the server should be responding with a 101.

This is the output from Autobahn:

2013-05-19 15:33:10+0100 [Uninitialized] connection to 127.0.0.1:8080 established
2013-05-19 15:33:10+0100 [Uninitialized] GET /ws HTTP/1.1
User-Agent: AutobahnPython/0.5.14
Host: localhost:8080
Upgrade: WebSocket
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Sec-WebSocket-Key: ZCnYpz0fvahS10S9aQWyvA==
Sec-WebSocket-Version: 8


2013-05-19 15:33:10+0100 [Uninitialized] TX Octets to 127.0.0.1:8080 : sync = False, octets = 474554202f777320485454502f312e310d0a557365722d4167656e743a204175746f6261686e507974686f6e2f302e352e31340d0a486f73743a206c6f63616c686f73743a383038300d0a557067726164653a20576562536f636b65740d0a436f6e6e656374696f6e3a20557067726164650d0a507261676d613a206e6f2d63616368650d0a43616368652d436f6e74726f6c3a206e6f2d63616368650d0a5365632d576562536f636b65742d4b65793a205a436e59707a306676616853313053396151577976413d3d0d0a5365632d576562536f636b65742d56657273696f6e3a20380d0a0d0a
2013-05-19 15:33:10+0100 [EchoClientProtocol,client] RX Octets from 127.0.0.1:8080 : octets = 485454502f312e31203430302042616420526571756573740d0a0d0a7061727365203a20656d7074792075726c
2013-05-19 15:33:10+0100 [EchoClientProtocol,client] received HTTP response:

HTTP/1.1 400 Bad Request




2013-05-19 15:33:10+0100 [EchoClientProtocol,client] received HTTP status line in opening handshake : HTTP/1.1 400 Bad Request
2013-05-19 15:33:10+0100 [EchoClientProtocol,client] received HTTP headers in opening handshake : {}
2013-05-19 15:33:10+0100 [EchoClientProtocol,client] failing WebSockets opening handshake ('WebSockets connection upgrade failed (400 - BadRequest)')
2013-05-19 15:33:10+0100 [EchoClientProtocol,client] dropping connection
2013-05-19 15:33:10+0100 [-] WebSocketProtocol.onClose:
wasClean=False
code=1006
reason=connection was closed uncleanly (None)
self.closedByMe=False
self.failedByMe=False
self.droppedByMe=True
self.wasClean=False
self.wasNotCleanReason=None
self.localCloseCode=None
self.localCloseReason=None
self.remoteCloseCode=None
self.remoteCloseReason=None

UPDATE: I have also tried against this sample Go code which is a very trivial echo server. This makes me even more suspicious of my Autobahn code.

UPDATE: Code, as requested:

package main

import (
    "net/http"
    "io"
    "code.google.com/p/go.net/websocket"
)

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

func main() {

    http.Handle("/ws", websocket.Handler(EchoServer));

    err := http.ListenAndServe(":8080", nil);
    if err != nil {
            panic("ListenAndServe: " + err.Error())
    }
}
doulian4762
doulian4762 我遇到了类似的问题。我切换到github.com/gorilla/websocket,然后一切正常。
大约 6 年之前 回复
douhuiqi3855
douhuiqi3855 您是否在Go服务器上尝试了JS客户端示例(github.com/tavendo/AutobahnPython/blob/master/examples/…)?
7 年多之前 回复
duanbei8904
duanbei8904 我在factory.protocol=EchoClientProtocol行之前添加了它,但它仍然给了我400。
7 年多之前 回复
dongzhina7098
dongzhina7098 通过查看Go服务器代码,URLws://localhost:8080/ws似乎是正确的(http.Handle(“/ws”,websocket.Handler(wsHandler)))。您可以在高速公路客户端中尝试factory.setProtocolOptions(version=18)。服务器应响应101。
7 年多之前 回复
douci1541
douci1541 与链接中的示例相同。无论如何我都提供了它。
7 年多之前 回复
dravpuso44681
dravpuso44681 您可以张贴服务器正在运行的go代码吗?这会很有帮助。
7 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐