Docsity

Getsockopt - Advanced Unix Programming - Lecture Slides, Slides of Computer Programming

Partial preview of the text

Download Getsockopt - Advanced Unix Programming - Lecture Slides and more Slides Computer Programming in PDF only on Docsity!

Week 9 Topics

• Socket options

  • getsockopt, setsockopt
  • fcntl
  • ioctl

• Introduction to UDP

  • TCP vs UDP
  • UDP interface

TCP vs UDP

• TCP

  • Reliable byte stream service
  • Connection setup overhead

• UDP

  • Unreliable datagram service
    • Data may get lost
      • Application may need to deal with more details in the communication

UDP interface

  • socket, bind, sendto, recvfrom, close

UDP server UDP client

socket socket bind sendto recvfrom recvfrom sendto close

TCP server TCP client

socket socket bind connect listen accept read/write close read/write close

UDP interface ... continued

  • #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 example1.c and example2.c for communication using UDP
  • Lost packets in UDP
    • How does the error rate vary with size of data?