Docsity

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

Partial preview of the text

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

Week 7 Topics

  • Basic TCP sockets
    • Socket address structure
    • Byte ordering and manipulation functions
    • socket, connect, bind, listen, accept
  • Client-Server design
    • Concurrent server

Basic TCP sockets

  • Socket address structure
  • Byte ordering and manipulation functions
  • socket, connect, bind, listen, accept

Network byte order

  • What happen when we run example2.c as server on program and example1.c as client on linprog?
  • sin_port and sin_addr must be in network byte order
  • Check example3.c
    • What is the difference between program and linprog?

Byte ordering functions

  • #include <arpa/inet.h>

uint16_t htons(uint16_t host16bitvalue); uint32_t htonl(uint32_t host32bitvalue); uint16_t ntohs(uint16_t net16bitvalue); uint32_t ntohl(uint32_t net32bitvalue);

  • See example3.c

Address conversion functions

  • #include <arpa/inet.h>
    • in_addr_t inet_addr(const char *cp);
    • char *inet_ntoa(struct in_addr in);
  • The ones below should be preferred
    • inet_ntop(address family, source, destination, size);
    • inet_pton(address family, source, destination);