Why a “java.net.SocketException: Broken pipe” will occur?

后端 未结 4 2048
梦谈多话
梦谈多话 2021-01-12 11:26

I wrote a simple socket programme, it works fine, but my friend use a port scanning tool, when it scan to the port I am using, it cash with \"java.net.SocketException: Broke

相关标签:
4条回答
  • 2021-01-12 12:20

    I think this happens when remote end closed the connection;

    0 讨论(0)
  • 2021-01-12 12:23

    The reason of your problem may be here:

    JavaDoc:

    The maximum queue length for incoming connection indications (a request to connect) is set to 50. If a connection indication arrives when the queue is full, the connection is refused.

    And you should increase "backlog" parameter of your ServerSocket, for example

    int backlogSize = 50 ;
    providerSocket = new ServerSocket(portNum, backlogSize);
    
    0 讨论(0)
  • 2021-01-12 12:26

    Either used throws clause with SocketException and IOException or put try catch finally as my friend suggested above.In finally dont forget to close all streams that you are using.And also check your port number at both client and server side programs.Hopw this will help.

    0 讨论(0)
  • 2021-01-12 12:28

    Some port scanners work by starting to open a connection and then immediately terminating it. Your server is not programmed to deal with a connection failure because you did not code for that possibility. You will need to use a try/catch to trap that condition and recover. Also, you should probably be handing off the connection to a separate thread for processing, so your main program can continue to receive new connections (and sending them to threads to be handled).

    0 讨论(0)
提交回复
热议问题