sockets

19/10/2010 20:50

In network programming, sockets popularly as "internet sockets" or"network sockets"

Defintion:
$ It is an end-point bidirectional inter-process communication folw for network dased protocol stack likt TCP across INTERNET
$  It is also called Application Programming Interface to provide  interface for TCp provided by os.

Main purpose:
<> It provides mechanism for delivering incoming data packets to appropriate application process or threads..
<> Every socket is mapped by os and communicationg application threads or process.

system calls associated with are:

1)socket():

   to create a new socket along with socket type ,unique integer identifier,allocation of resources for it
2)bind():

    on a server side it assocites(bind) each socket with a unique socket structure(having local IP address and local port)
3)listen():

    on a server side,cause tcp socket bounds to enterlistening state
4)connect():

    on a client side,client alocates a free local port number to each socket..to get coonect on with server
5)accept():

      on a server side,it grants connection to client eg in case of TCp connection
6)select():

       to select list of sockets that are readt to write ,read or with errors
7)poll():

  to check state of socket wheter it is in error,read,write etc
8)read() write() send()recv()sendto()  recvfrom()  sendto() :

         These are asscocated with read/write data packets
9)close():

        To release the resources allocated for each socket at end of connection:

command to check current  socket connections in ms windows"
netstat
e.g

C:\Documents and Settings\admin>netstat

Active Connections

  Proto  Local Address          Foreign Address        State
  TCP    intel:3440             bom01s01-in-f83.1e100.net:https  ESTABLISHED
  TCP    intel:3446             bom01s01-in-f83.1e100.net:https  TIME_WAIT
  TCP    intel:3449             bom01s01-in-f83.1e100.net:https  TIME_WAIT
  TCP    intel:3450             bom01s01-in-f83.1e100.net:https  TIME_WAIT
  TCP    intel:3451             bom01s01-in-f83.1e100.net:https  TIME_WAIT
  TCP    intel:3452             193.66.251.211:http    CLOSE_WAIT
  TCP    intel:3453             bom01s01-in-f83.1e100.net:https  TIME_WAIT
  TCP    intel:3454             bom01s01-in-f83.1e100.net:https  TIME_WAIT
  TCP    intel:3455             bom01s01-in-f83.1e100.net:https  TIME_WAIT
  TCP    intel:3456             bom01s01-in-f83.1e100.net:https  TIME_WAIT
  TCP    intel:3458             fxfeeds.acelb.sj.mozilla.com:http  CLOSE_WAIT
  TCP    intel:3459             172.16.10.143:http     SYN_SENT
  TCP    intel:3460             bbc-vip106.telhc.bbc.co.uk:http  CLOSE_WAIT