setSoTimeout on a client socket doesn't affect the socket

前端 未结 2 1311
天涯浪人
天涯浪人 2021-01-23 19:52

I have a Java application with three threads that open, each, a socket and connect to a server on different ports. I set so_timeout on each of these sockets after the connection

2条回答
  •  悲&欢浪女
    2021-01-23 20:21

    I've had several problems in the past dealing with SO_TIMEOUT in windows. I believe setting this is "supposed" to set the underlying socket implementation that could be OS dependent and conflicting with registry settings and such.

    My advice is to not use SO_TIMEOUT to force a thrown exception on a timeout. Use either non-blocking I/O or check that you have bytes available() before you read().

提交回复
热议问题