golang websocket 连接的问题

lywsbcn · · 2557 次点击
http.Handle("/", websocket.Handler(listener)) if err := http.ListenAndServe(":1414", nil); err != nil { log.Println("ok") } 改成: http.Handle("/", websocket.Handler(listener)) if err :=http.ListenAndServe(":1414", websocket.Server{websocket.Config{},nil,listener}); err != nil { log.Println("ok") } 问题解决了
#8
更多评论
如果这样的话,感觉是不是 Android 代码有问题?
#1
安卓代码,连其他的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