这是我从中获取 socketIO 文件的地方。 https://github.com/Gottox/socket.io-java-client/tree/master/src/io/socket
我在客户端。我知道当服务器不需要身份验证时连接有效。
但是当它需要身份验证(用户名和密码)时,我会收到一条握手错误消息。
我如何获得通过身份验证?会不会是服务器端错误?如果添加了身份验证,服务器端的事情会改变吗?
这是抛出错误的函数......我没有写它。这一行是导致问题的原因: InputStream stream = connection.getInputStream(); 它说它是由以下原因引起的:java.io.FileNotFoundException: url:80/socket.io/1/
private void handshake() {
URL url;
String response;
URLConnection connection;
try {
setState(STATE_HANDSHAKE);
url = new URL(IOConnection.this.url.toString() + SOCKET_IO_1);
connection = url.openConnection();
if (connection instanceof HttpsURLConnection) {
((HttpsURLConnection) connection)
.setSSLSocketFactory(sslContext.getSocketFactory());
}
connection.setConnectTimeout(connectTimeout);
connection.setReadTimeout(connectTimeout);
/* Setting the request headers */
for (Entry<Object, Object> entry : headers.entrySet()) {
connection.setRequestProperty((String) entry.getKey(),
(String) entry.getValue());
}
InputStream stream = connection.getInputStream();
Scanner in = new Scanner(stream);
response = in.nextLine();
String[] data = response.split(":");
sessionId = data[0];
heartbeatTimeout = Long.parseLong(data[1]) * 1000;
closingTimeout = Long.parseLong(data[2]) * 1000;
protocols = Arrays.asList(data[3].split(","));
} catch (Exception e) {
error(new SocketIOException("Error while handshaking", e));
}
}