Stop and wait socket programming with UDP

Looking to make a Java stop-and-wait UDP server and client but I'm running into some problems starting off. I've made a simple UDP client and server without the stop-and-wait part, but I would now like to learn how to change it. How can I send ACKs and implement timeouts using java sockets ?

Could someone please post up some examples for me to use in my implementation ?

8

1 Answer

If you're implementing this in UDP, sending and receiving acknowledgements is up to you. This seems to be what you want for this stop and wait protocol. In terms of pseudocode, you would want something like:

int Send(msg)
{ char rcvBuf[]; sentBytes = sock.send(msg); sock.rcv(rcvBuf); return sentBytes;
}
int Recv(rcvBuf)
{ String ackMsg = "ACK"; length = sock.rcv(rcvBuf); sock.send(ackMsg); return length;
}

After every send, you wait for an acknowledgement message to come in, and every time you receive, you send an acknowledgement.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like