how can i stop the block method DatagramSocket.receive() in a thread

后端 未结 3 1651
情书的邮戳
情书的邮戳 2020-12-11 02:47

i create a DatagramSocket in the main thread,and then create a inner class thread to listen the port. when i close the DatagramSocket in the main t

3条回答
  •  醉话见心
    2020-12-11 03:26

    With UDP, you could send the socket a datagram from another thread, so unblocking the read(). The datagran could, (depending on your protocol), contain a 'suicide' command or you could use an additional 'shutdown' boolean that the thread reads after read() returns.

提交回复
热议问题