I am just fiddling around with making a UDP chat program that simply allows messages to be sent between two clients. I am using the DatagramSocket and DatagramPacket classes. The issue that I’m running into is when one client is waiting to receive a Datagram from the other client, using receive, then I can’t send any messages with that client as its I/O is blocked, so my current version only allows one message back and forth at a time. What I’m trying to accomplish it to allow the receive method to listen and run separately from the sending portion of the code so that the users can send as many messages as they want without waiting for a reply. Any advice for examples would be greatly appreciated. Thanks.
Share
You’ll need two threads at each end, one to receive messages (and display them), and another to receive user input and send those messages.