Compiled by: Jayakumar Balasubramanian Web:  http://www.jwritings.com Email:  [email_address]
Introduction <ul><li>Introduction to sockets </li></ul><ul><li>The “Endian” concept </li></ul><ul><li>Trivial functions </...
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 () <ul><li>Use to create a socket. </li></ul><ul><li>fd = socket (family, type, protocol) </li></ul><ul><li>F...
API: bind() [The anchor]
API: bind() <ul><li>Attach a transport address to a socket. </li></ul><ul><li>status = bind (fd, addressp, addrlen); </li>...
API: connect()
API : connect() <ul><li>The connect function is used by a TCP client to </li></ul><ul><li>establish a connection with a TC...
API: listen()
API: listen() <ul><li>listen() </li></ul><ul><li>Prepares a socket to accept connections </li></ul><ul><li>Must be used on...
API : accept()
API : accept() <ul><li>Used in the server side of the connection to accept incoming new connections </li></ul><ul><li>When...
Connection establishment
API : send() <ul><li>Sends data over a communication channel </li></ul><ul><li>Can be used in server and client side </li>...
API : recv() <ul><li>R eceives data over a communication channel </li></ul><ul><li>Can be used in server and client side <...
API: close() <ul><li>Close terminates both directions of data transfer, reading and writing.  </li></ul><ul><li>close( soc...
Web  :  http://www.jwritings.com Email:  [email_address]
Upcoming SlideShare
Loading in …5
×

Networking chapter III

619 views

Published on

Networking chapter - III is about doing network programming using sockets.

Published in: Technology, Education

Networking chapter III

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

×