Java socket, Is that a dead lock or what?

后端 未结 2 969
小蘑菇
小蘑菇 2021-01-21 00:30

I have a client-server program using socket on the server side and read and write is happening in that way

soc = serversocket.accept();
System.out.println(\"Acce         


        
相关标签:
2条回答
  • It's not a deadlock, just bad code. You keep calling readUTF() and then throwing the result away and calling it again, as though the same thing was being sent as many times as you are calling it, which it isn't. So you are blocking, in the redundant calls to readUTF().

    So don't do that. Call it once and store the result in a variable.

    And it will never return null. Check the Javadoc.

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

    Its a deadlock, you must create and flush the ObjectOutputStream first. This is because ObjectInputStream reads the header sent by the OOS before continuing.

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