java timer and socket problem

后端 未结 3 1254
再見小時候
再見小時候 2020-12-21 11:28

I\'m trying to make a program which listens to the client input stream by using socket programming and timer

but whenever timer executes.. it gets hanged

Ple

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-21 11:58

    Every call to accept waits for a new client to connect to the server. The call blocks until a connection is established. It sounds like you have a single client that maintains a connection to the server.

    One solution is to pull

    s=ss.accept();                    
    InputStream is=s.getInputStream();
    DataInputStream dis=new DataInputStream(is);
    

    outside of the timer portion of the code.

    Update: Be aware though that readUTF is still going to block if there is no data available to be read.

提交回复
热议问题