35-NetworkTCP - CS 241 Spring 2008 System Programming TCP...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 241 Spring 2008 System Programming 1 TCP Programming and the TCP/IP Protocol Learning Objectives API calls required to establish and use a versions Common mistakes / misconceptions TCP/IP Protocol foundations Host name resolution Lawrence Angrave
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Socket-Based APIs #include <sys/ socket.h int  socket  (int domain, int type, int protocol);  int  bind  (int s, struct sockaddr *address,  size_t address_len);  int  listen  (int s, int backlog);  int  accept  (int s, struct sockaddr *address, int* address_len); 
Background image of page 2
3 Socket Creation in C: socket int s = socket( AF_INET , SOCK_STREAM , 0 ); s: socket descriptor, an integer AF_INET : Internet domain (communication domain) communication type SOCK_STREAM : reliable, 2-way, connection-based service SOCK_DGRAM: unreliable, connectionless (UDP), other values: need root permission, rarely used, or obsolete
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Socket Structure The format of the address struct sockaddr is determined by the address family (domain). For AF_INET it is a struct sockaddr_in Socket structure is defined in netinet/in.h Socket structure has at least the following members in network byte order: sa_family_t sin_family; in_port_t sin_port; /* Host Port Number */ struct in_addr sin_addr; /* IP Address*/
Background image of page 4
5 Bind Function int bind(int s, const struct sockaddr *address, size_t address_len); Bind function Associates the handle for a socket communication endpoint with a specific logical network connection. Note: Internet domain protocols specify logical connection by a port number s is the file descriptor returned by socket( ) address contains info about the family, port and machine address_len is the size of the structure used for the address
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 SOCK_STREAM (TCP) Connection Setup Recall: no connection setup for SOCK_DGRAM A connection setup has two participants passive : waits for an active participant to request connection active : initiates connection request to passive side However once connection is established, both passive and active participants can Terminate the connection
Background image of page 6
7 Connection sequence Passive participant step 1: listen (for incoming requests) step 3: accept (a request) step 4: data transfer (on new socket) The accepted connection is on a new socket The old socket continues to listen for other active participants Active participant connect ion step 4: data transfer Passive Participant l-sock a-sock-1 a-sock-2 Active 1 socket Active 2 socket
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 int listen (int s, int backlog); 0 if listening, -1 if error s : socket descriptor backlog
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/04/2008 for the course CS 241 taught by Professor Systemsprogramming during the Spring '08 term at University of Illinois at Urbana–Champaign.

Page1 / 29

35-NetworkTCP - CS 241 Spring 2008 System Programming TCP...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online