Thursday, 11 August 2011

UDP Program Steps


                                                       Udp Client Server Communication  (Connection less  service )


Algorithm Steps:

Server:

1. Create a socket using socket() system call.

2. Bind socket to port number using bind() system call.

3. Inside a loop wait for the client to send some message.

4. Receive a message using recvfrom() system call.

5. If received message is ‘bye’, send message ‘bye’ and stop the chat.  If not, send some message using sendto() system call.


Client:

1. Create a socket using socket() system call.

2. Inside a loop, type a message to be send to server.

3. Send the message using sendto() system call.

4. Receive the message from server using recvfrom() system call.

5. If the message received or send is ‘bye’ then stop.

6. Close the socket.

7. Stop.





TCP Socket Creation:

socket(AF_INET,SOCK_STREAM,0);

 UDP Socket creation:

sd = socket(AF_INET, SOCK_DGRAM, 0);


bind(sd,(struct sockaddr *)&servaddr, sizeof(struct sockaddr));


recvfrom(sd,recv_data,1024,0,
                   (struct sockaddr *)&client_addr, &addr_len);

 sendto(sd, send_data, strlen(send_data), 0,
              (struct sockaddr *)&servaddr, sizeof(struct sockaddr));

No comments:

Post a Comment