简体   繁体   English

socket.io和Java-连接失败

[英]socket.io and java - connection failure

I cannot connect to my node.js server from java using socket.io-java-client from gottox . 我无法使用gottox的 socket.io-java-client从Java连接到我的node.js服务器。 I followed the build recommendation for socket.io v. 1.0.6 from beenjaminn here . 我遵循socket.io诉构建建议。从beenjaminn 1.0.6 这里

Here is my connect command: 这是我的连接命令:

socket.connect("http://192.168.1.7:8000/", this);

Here is the resulting error: 这是导致的错误:

an Error occured
io.socket.SocketIOException: Error while handshaking
    at io.socket.IOConnection.handshake(IOConnection.java:323)
    at io.socket.IOConnection.access$7(IOConnection.java:293)
    at io.socket.IOConnection$ConnectThread.run(IOConnection.java:200)
Caused by: java.io.IOException: Server returned HTTP response code: 400 for     
URL: http://192.168.1.7:8000/socket.io/1/player
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1839)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
    at io.socket.IOConnection.handshake(IOConnection.java:314)
    ... 2 more
Jul 03, 2015 11:08:38 AM io.socket.IOConnection cleanup
INFO: Cleanup

From javascript using the socket.io npm module I can connect fine. 从使用Socket.io npm模块的javascript中,我可以正常连接。

var socket = io("http://" + location.host + "/player", {reconnection: false});

Note that the javascript client first requests an html page from 192.168.1.7:8000 which downloads the js above which then makes the websocket connection in the line above. 请注意,javascript客户端首先从192.168.1.7:8000请求html页面,该页面下载上面的js,然后在上面的行中建立websocket连接。

What is wrong with my java client connection? 我的Java客户端连接有什么问题?

I found this alternate implementation for the java client from nkzawa. 我从nkzawa找到了Java客户端的此替代实现 It worked right out of the box. 它开箱即用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM