Thursday, January 30, 2014

Understanding Socket Programming Part 1

What is a Socket?

  • Allows to communicate between two process on the same or different machines.
  • A way to talk to other computers using standard Unix file descriptors(Unix File Descriptors- click here)

Assume a situation in which a client want to connect to a server. The client knows the hostname of the machine that runs the server and also the port number at which the server listens for connection.

A server is a process which does some function on request from a client. Most of the application level protocols like FTP, SMTP and POP3 make use of Sockets to establish connection between client and server and then for exchanging data.




Client sent a connection request to server: The client tries to rendezvous with the server on the server's machine and port.

Server accepts connection: The server gets a new socket bound to the same local port and also has its remote endpoint set to the address and port of the client







Definition

socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent.


Links that could help you:

http://programmers.stackexchange.com/questions/171734/difference-between-a-socket-and-a-port
http://www.tutorialspoint.com/unix_sockets/what_is_socket.htm


Tags:-client, server, socket, programming,file descriptor

1 comment:

  1. http://beej.us/guide/bgipc/output/html/multipage/unixsock.html

    ReplyDelete