11:21 PM Socket programming in C |
Most inter-process communication uses the client server model. These terms refer to the two processes which will be communicating with each other. One of the two processes, the client, connects to the other process, the server, typically to make a request for information. A socket is one end of an inter-process communication channel. The two processes each establish their own socket. The steps involved in establishing a socket on the client side are as follows:
The steps involved in establishing a socket on the server side are as follows:
Socket TypesWhen 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). 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. The examples in this tutorial will use sockets in the Internet domain using the TCP protocol. Sample codeC code for a very simple client and server are provided for you. These communicate using stream sockets in the Internet domain. The code is described in detail below. However, before you read the descriptions and look at the code, you should compile and run the two programs to see what they do. tcpserver.c |
|
Related blogs
You may also like to see:
[2014-02-05] | [Technical Solution] |
How do we use FTP from command line to send and receive files |
[2014-02-06] | [Technical Solution] |
tzutil time zone utility to set time zone of the computer using command line |
[2014-01-28] | [Technical Solution] |
How to design a 3D object for a game using Blender. |
[2014-12-28] | [Technical Solution] |
How to schedule a mail in outlook to be sent later? |
[2015-03-28] | [Technical Solution] |
Control your Samsung mobile remotely : lock, track, wipe data when lost |
Total comments: 0 | |