I want to send data to server, then wait for an answer for one minute and then close the socket.
How to do it?
DatagramPacket sendpack = new ......;
socket.send(pack);
DatagramPacket recievepack = new .....;
//wait 1 minute{
socket.recieve(buf);
//wait 1 minute}
socket.close();
To clarify EJP's comment, this is what he meant by a "missing
break
" causing a SocketException.If you are using DatagramSocket, or Socket you can use,
For any detail, you should've taken a look in DatagramSocket javadoc or Socket javadoc.
You can try this. Change the timeout of the socket as required in your scenario! This code will send a message and then wait to receive messages until the timeout is reached!