1 / 11

Programming a UDP client

Programming a UDP client. Find the IP address and protocol port number of the server with which communication is desired Allocate a socket Specify that the communication needs an arbitrary, unused protocol port on the local machine, and allow UDP to choose one.

keona
Download Presentation

Programming a UDP client

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming a UDP client • Find the IP address and protocol port number of the server with which communication is desired • Allocate a socket • Specify that the communication needs an arbitrary, unused protocol port on the local machine, and allow UDP to choose one. • Specify the server to which messages must be sent • Communicate with the server using the application-level protocol(this usually involves sending requests and awaiting replies) • Close the socket

  2. continued • A connectionless client • The sending process creates a connected socket and uses it to send one or more requests iteratively • This algorithm ignores the issue of reliability

  3. Connected and unconnected UDP sockets • Client application can use a UDP socket in one of two basic modes: connected and unconnected • UDP can be connected, making it convenient to interact with a specific server, • UDP can be unconnected, making it necessary for the application to specify the server’s address each time it sends a message

  4. Using connect with UDP • Client can connect a socket of type SOCK_DGRAM • Connect call doesnot initiate any package exchange • Does not test validity of the remote endpoint address • It merely records the remote endpoint information in the socket data structure for later use • Even if the connect call succeeds, it doesn’t mean that the remote endpoint address is valid or that server is reachable

  5. Communicating with a server using UDP • After a UDP client calls connect, it can use send to send a message or recv to receive a response. • Each time the client call send, UDP sends a single message to the server • Message contain all data to be sent • Similarly, each call to recv returns one complete message. • If the user’s buffer is not large enough, UDP discards bytes from the message that do not fit in the buffer

  6. Closing a socket that uses UDP • A UDP client calls close to close a socket and release the resources associated with it. • Once a socket has been closed, the UDP software will reject further messages that arrive. • It does not inform the remote endpoint that the socket is closed. • Application must be designed so the remote side knows how long to retain a socket before closing

  7. Iterative, connectionless server • Iterative server work best for services that have a low request processing time. Algorithm • Create a socket and bind to the well-known address for the service being offered • Repeatedly read next request from a client, formulate a response, and send a reply back to the client according to the application protocol

  8. Forming a reply address • A connectionless server cannot use connect because doing so restricts the socket to communication with one specific remote host and port;the server cannot use socket again to receive datagrams from arbitrary clients. • Thus, a connectionless server uses an unconnected socket

  9. sendto int sendto( int s, // socket descriptor const char *buff, // message int len, // length of message int flag, // 0 struct sockaddr *addrptr, //server add int addlen); // size of server add

  10. recvfrom() int recvfrom( int s, // socket desc char *buff, // message int len, // length int flag, // 0 struct sockaddr *addrptr, //client int *addrlen); //size of client

  11. recvfrom • int recvfrom( int s, const char *buff, int len, int flag, struct sockaddr *addrptr, int *len);

More Related