0

每次都遇到类似 java.net.SocketException 的错误

in java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.io.FilterInputStream.read(Unknown Source)
    at Server.TcpServer.main(TcpServer.java:37)
my code at the following line....

phonenumber = Long.parseLong(query, inFromTcpClient.read());
thanks in advance...
4

2 回答 2

0

要解决此问题,客户端需要在管理员模式下运行其命令提示符,然后键入命令:

netsh advfirewall set global StatefulFTP disable 

这应该可以防止 java.net.Socket 的实例过早关闭其连接。

也检查这个链接

于 2013-11-18T10:47:30.677 回答
0

听起来您还没有进入.accept循环,这意味着客户端和服务器之间的连接就像 Eclipse 所说reset的那样,它所做的只是连接,然后断开连接。

一般是这样的

try {
    while (true) {
        Socket socket = server.accept();
        // do something with socket (and close it afterwards!)
    }
} catch (InterruptedException ex) {
    // we're outta here!
}
于 2013-11-18T10:38:59.037 回答