Send and receive serialize object on UDP

后端 未结 2 1066
囚心锁ツ
囚心锁ツ 2020-12-10 05:17

I am trying to send a serialized object from a server process to a client process in Java using UDP. The problem is that the client is being blocked on the receive method. C

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 05:33

    I didnt really test it, but I am pretty sure - based on the description - that the datagramsocket.reseive function will block until the packet is filled (in your case until 100000 bytes are received).

    This is wrong. The receive function will block until a datagram is received, which can be smaller than the buffer size (and usually will be). The method packet.getLength() will tell you how big it was.

提交回复
热议问题