```go
import (
"log"
"net/http"
"golang.org/x/net/websocket"
)
func main() {
http.Handle("/", websocket.Handler(listener))
if err := http.ListenAndServe(":1414", nil); err != nil {
log.Println("ok")
}
}
func listener(ws *websocket.Conn) {
var err error
for {
var request string
if err = websocket.Message.Receive(ws, &request); err != nil {
log.Println("连接断开!!")
break
}
log.Println("客户端请求 : " + request)
}
}
```
上面的websocket 连接 在ios客户端 和web浏览器上面 连接都没有问题
但是到了,Android上就打开了连接,但是马上的断开了连接
```
09-24 14:16:00.829 8871-8871/com.jh.websoket D/de.tavendo.autobahn.WebSocketConnection: opening handshake received
09-24 14:16:00.829 8871-8871/com.jh.websoket I/fajflajflajflaj: onOpen:
09-24 14:16:00.829 8871-8871/com.jh.websoket D/de.tavendo.autobahn.WebSocketConnection: fail connection [code = 3, reason = WebSockets connection lost
09-24 14:16:00.829 8871-8871/com.jh.websoket D/de.tavendo.autobahn.WebSocketReader: quit
09-24 14:16:00.830 8871-8942/com.jh.websoket D/de.tavendo.autobahn.WebSocketWriter: ended
09-24 14:16:00.831 8871-8871/com.jh.websoket I/fajflajflajflaj: onClose: 3|WebSockets connection lost
09-24 14:16:00.832 8871-8871/com.jh.websoket D/de.tavendo.autobahn.WebSocketConnection: worker threads stopped
```
上面是报错信息
请问,我哪里做错了吗
安卓代码,连其他的websocket 是可以连接上去的,贴上代码
```java
private WebSocketConnection mConnect = new WebSocketConnection();
public void init() {
String url = "ws://192.168.1.227:1414";
try {
mConnect.connect(url, new WebSocketHandler() {
@Override
public void onOpen() {
Log.i(TAG, "onOpen: ");
mConnect.sendTextMessage("hha");
}
@Override
public void onTextMessage(String payload) {
Log.i(TAG, "onTextMessage: "+payload);
}
@Override
public void onClose(int code, String reason) {
Log.i(TAG, "onClose: " + code + "|" + reason);
}
});
} catch (WebSocketException e) {
e.printStackTrace();
}
}
```
#2
更多评论