Prerequisites :
Before you start learning socket programming make sure you already have a certain basic knowledge to network such as understand what is IP address, TCP, UDP.
Introduction to Client-Server communication
Server
- passively waits for and responds to clients
- passive socket
Client
- initiates the communication
- must know the address and the port of the server
- active socket
The server and client both are software but not hardware. It means what is happening on the top is there are two different software executed. To be more precise, the server and client are two different processes with different jobs.
Understand sockets
Imagine a socket as a seaport that allows a ship to unload and gather shipping, whereas socket is the place where a computer gathers and puts data into the internet.
When a socket is created, the program has to specify the address domain and the socket type. Two processes can communicate with each other only if their sockets are of the same type and in the same domain. There are two widely used address domains, the unix domain, in which two processes which share a common file system communicate, and the Internet domain, in which two processes running on any two hosts on the Internet communicate. Each of these has its own address format.The address of a socket in the Unix domain is a character string which is basically an entry in the file system.
The address of a socket in the Internet domain consists of the Internet address of the host machine (every computer on the Internet has a unique 32 bit address, often referred to as its IP address). In addition, each socket needs a port number on that host. Port numbers are 16 bit unsigned integers. The lower numbers are reserved in Unix for standard services. For example, the port number for the FTP server is 21. It is important that standard services be at the same port on all computers so that clients will know their addresses. However, port numbers above 2000 are generally available.
There are two widely used socket types, stream sockets, and datagram sockets. Stream sockets treat communications as a continuous stream of characters, while datagram sockets have to read entire messages at once. Each uses its own communciations protocol. Stream sockets use TCP (Transmission Control Protocol), which is a reliable, stream oriented protocol, and datagram sockets use UDP (Unix Datagram Protocol), which is unreliable and message oriented.
Sockets - Procedures
Primitives Meaning
Socket Create New Communication End Point
Bind Attach A Local Address To Socket
Listen Announce Willingness to Accept Connections
Accept Block A Caller until Connection Request Arrives
Connect Actively Attempt to establish a Connection.
Send Send some data over Connection.
Receive Receive data over the connection
Close Close the connection.
Bind Attach A Local Address To Socket
Listen Announce Willingness to Accept Connections
Accept Block A Caller until Connection Request Arrives
Connect Actively Attempt to establish a Connection.
Send Send some data over Connection.
Receive Receive data over the connection
Close Close the connection.
The flow chart below shows the interaction between client and server In Case Of Stream(TCP). Every process on the flow chart is needed and it acts a very important roles on network connection.
For Details Refer To Link:
http://www.codeproject.com/Articles/586000/Networking-and-Socket-programming-tutorial-in-C
For Programming Details Refer:
http://www.cs.rpi.edu/~moorthy/Courses/os98/Pgms/socket.html
No comments:
Post a Comment