1 / 17

Review: How to create a TCP end point?

Explore UDP introduction, server design options, and TCP communication details including socket, bind, sendto, recvfrom and more. Learn about UDP relevance and performance impact in various applications.

calexander
Download Presentation

Review: How to create a TCP end point?

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. Review: • How to create a TCP end point? • What is the right format for sin_port and sin_addr in the sockaddr_in data structure? • How many different ways we can bind a socket?

  2. How to specify the maximum number of connections for a socket? • How to find out the remote machine information?

  3. Today’s topic: • Introduction to UDP • Some server design alternatives • Select

  4. TCP: Reliable byte stream service. • Different ways to build client/servers • How to get around blocking I/O • Assumption: whatever sent will eventually be received!! • UDP: Unreliable datagram service. • Data may get lost – application may need to deal with more details in the communication.

  5. Why UDP: • Applications that do not need 100% reliability communication. E.g VoIP, video stream, DNS servers. • Applications care a lot about performance: high performance computing (TCP cares too much about fairness). • Applications that need multicast or broadcast (TCP only supports point to point communication).

  6. UDP server client socket socket bind sendto recvfrom recvfrom Sendto close TCP server client socket socket Bind connect Listen … … close close • Basic UDP service interface: • Socket, bind, sendto, recvfrom, close

  7. #include <sys/socket.h> ssize_t recvfrom(int sockfd, void *buff, size_t nbytes, int flags, struct sockaddr *from, socklen_t *addrlen); ssize_t sendto(int sockfd, void *buff, size_t nbytes, int flags, const struct sockaddr *to, socklen_t addrlen); See udpsender.c/udprecv.c for communication using UDP.

  8. Server design alternatives: concurrent and multiplexed server. • Concurrent server (see lect3/example5.c): • Use a new child process to handle a new connection requests.

  9. Multiplexed Server: The use of select. • I/O multiplexing – check the file descriptor before performing a blocking operation (what happen to the client when a concurrent server clushs?).

  10. The select function that allows: • To detect any of the descriptors in the read set are ready for reading. • To detect any of the descriptors in the write set are ready for writing • To detect any of the descriptors in the error set have exception conditions pending. • To wait for a period for something to happen.

  11. #include <sys/select.h> #include <sys/time.h> int select (int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout)

  12. Set the timeout value: Struct timeval { long tv_sec; /* seconds */ long tv_usec; /* microseconds */ } • Wait forever (blocking select): timeout = NULL • Non blocking select (return right away: tv_sec = 0; tv_usec = 0; • Wait for a certain amount of time: tv_sec and tv_usec

  13. Set the set of file descriptors value: void FD_ZERO(fd_set *fdset) void FD_SET(int fd, fd_set *fdset) void FD_CLR(int fd, fd_set *fdset) void FD_ISSET(int fd, fd_set *fdset)

  14. Maxfdp1: the maximum file descriptor number plus 1. (can just specify a big number (64) if unknown). • Select clears the uninteresting file descriptors in the fd_sets – always reset the fd_sets before calling select.

  15. When is a socket ready for read? • The number of bytes in the socket is more than the low-water mark (can be set, default 1 for TCP/UDP socket) • Half of the connection is closed • Listening socket with nonzero of completed connections • Socket error.

  16. When is a socket ready for write? • The available buffer space is larger than the low-water mark • Half the connection is closed • Error pending • Exception? • Out of band data exists.

  17. A multiplexed server (multiserv.c) • A single process to handle everything including connection request and data processing. • Using select the check on all descriptors that might need communication. • Response to whatever from the clients.

More Related