UDP Socket Programming - 2
UDP Socket Programming - 2
I. The client does not form a connection with the server like in TCP and
instead just sends a datagram.
II. Similarly, the server need not accept a connection and just waits for
datagrams to arrive
UDP Server:
1. Create UDP socket.
2. Bind the socket to server address.
3. Wait until datagram packet arrives from client.
4. Process the datagram packet and send a reply to client.
5. Go back to Step 3.
>> Sample Server side dummy code in UDP has been written below
int main() {
int sockfd;
char buffer[MAXLINE];
char *hello = "Hello from server";
struct sockaddr_in servaddr, cliaddr;
return 0;
}
UDP Client:
1. Create UDP socket.
2. Send message to server.
3. Wait until response from server is received.
4. Process reply and go back to step 2, if necessary.
5. Close socket descriptor and exit.
>> Sample Client side dummy code in UDP has been written below
int main() {
int sockfd;
char buffer[MAXLINE];
char *hello = "Hello from client";
struct sockaddr_in servaddr;
close(sockfd);
return 0;
}