Compiled by: Jayakumar Balasubramanian Web:  http://www.jwritings.com Email:  [email_address]
Introduction Introduction to sockets The “Endian” concept Trivial functions Socket APIs Client server programming using sockets
Introduction
The “Endian” concept
Big-Endian
Little-Endian
Bit order transformation
Trivial functions
How does one talk to TCP/IP ?
Addressing in IP and TCP
Socket address
Socket APIs
API : Socket () Use to create a socket. fd = socket (family, type, protocol) Family  : AF_INET, AF_UNIX, AF_NS  Type  : SOCK_STREAM, SOCK_DGRAM Protocol  : Protocol for a given socket
API: bind() [The anchor]
API: bind() Attach a transport address to a socket. status = bind (fd, addressp, addrlen); fd  :  Socket descriptor addressp :  Pointer to address structure addrlen  : Size of address structure
API: connect()
API : connect() The connect function is used by a TCP client to establish a connection with a TCP server  int fd, status, addrlen; struct sockaddr  *addressp; status = connect (fd, addresssp, addrlen);
API: listen()
API: listen() listen() Prepares a socket to accept connections Must be used only on the server side of the application before any connection request is accepted. int fd, qlen, status;   status = listen (fd, qlen);  fd  : Socket descriptor  qlen  : Length of the queue
API : accept()
API : accept() Used in the server side of the connection to accept incoming new connections When requests arrives it creates new socket, accepts the connection on the new socket int newfd, addrlen; struct sockaddr  * addressp; newfd = accept (fd, addressp, & addrlen);
Connection establishment
API : send() Sends data over a communication channel Can be used in server and client side   int fd, len, flags;   char *buff;   sent = send (fd, buff, len, flags);   sent can be <= len
API : recv() R eceives data over a communication channel Can be used in server and client side   int fd, len, flags, received;   char *buff; received = recv (fd, buff, len, flags);
API: close() Close terminates both directions of data transfer, reading and writing.  close( sockfd)
Web  :  http://www.jwritings.com Email:  [email_address]

Networking chapter III

  • 1.
    Compiled by: JayakumarBalasubramanian Web: http://www.jwritings.com Email: [email_address]
  • 2.
    Introduction Introduction tosockets The “Endian” concept Trivial functions Socket APIs Client server programming using sockets
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
    How does onetalk to TCP/IP ?
  • 10.
  • 11.
  • 12.
  • 13.
    API : Socket() Use to create a socket. fd = socket (family, type, protocol) Family : AF_INET, AF_UNIX, AF_NS Type : SOCK_STREAM, SOCK_DGRAM Protocol : Protocol for a given socket
  • 14.
  • 15.
    API: bind() Attacha transport address to a socket. status = bind (fd, addressp, addrlen); fd : Socket descriptor addressp : Pointer to address structure addrlen : Size of address structure
  • 16.
  • 17.
    API : connect()The connect function is used by a TCP client to establish a connection with a TCP server int fd, status, addrlen; struct sockaddr *addressp; status = connect (fd, addresssp, addrlen);
  • 18.
  • 19.
    API: listen() listen()Prepares a socket to accept connections Must be used only on the server side of the application before any connection request is accepted. int fd, qlen, status; status = listen (fd, qlen); fd : Socket descriptor qlen : Length of the queue
  • 20.
  • 21.
    API : accept()Used in the server side of the connection to accept incoming new connections When requests arrives it creates new socket, accepts the connection on the new socket int newfd, addrlen; struct sockaddr * addressp; newfd = accept (fd, addressp, & addrlen);
  • 22.
  • 23.
    API : send()Sends data over a communication channel Can be used in server and client side int fd, len, flags; char *buff; sent = send (fd, buff, len, flags); sent can be <= len
  • 24.
    API : recv()R eceives data over a communication channel Can be used in server and client side int fd, len, flags, received; char *buff; received = recv (fd, buff, len, flags);
  • 25.
    API: close() Closeterminates both directions of data transfer, reading and writing. close( sockfd)
  • 26.
    Web : http://www.jwritings.com Email: [email_address]