Linux-redhat-network-programming

Posted by Satriopiningit | Posted in Linux OS | Posted on 09-11-2008-05-2008

9

The basic concepts you need for network programming:

  1. Ports and sockets
  2. Record and file locking
  3. Interprocess communications

It is impossible to tell you how to program applications for a network in just a few pages. Indeed, the best reference to network programming available takes almost 800 pages in the first volume alone! If you really want to do network programming, you need a lot of experience with compilers, TCP/IP, network operating systems, and a great deal of patience.

Ports and Sockets

Network programming relies on the use of sockets to accept and transmit information. Although there is a lot of mystique about sockets, the concept is actually very simple to understand. Most applications that use the two primary network protocols, Transmission Control Protocol (TCP) or User Datagram Protocol (UDP) have a port number that identifies the application. A port number is used for each different application the machine is handling, so it can keep track of them by numbers instead of names. The port number makes it easier for the operating system to know how many applications are using the system and which services are available. In theory, port numbers can be assigned on individual machines by the system administrator, but some conventions have been adopted to allow better communications. This convention enables the port number to identify the type of service that one system is requesting from another. For this reason, most systems maintain a file of port numbers and their corresponding services. Port numbers are assigned starting from the number 1. Normally, port numbers above 255 are reserved for the private use of the local machine, but numbers between 1 and 255 are used for processes requested by remote applications or for networking services. Each network communications circuit that goes into and out of the host computer’s TCP application layer is uniquely identified by a combination of two numbers, together called the socket. The socket is composed of the IP address of the machine and the port number used by the TCP software. Because there are at least two machines involved in network communications, there will be a socket on both the sending and receiving machine. The IP address of each machine is unique, and the port numbers are unique to each machine, so socket numbers will also be unique across the network. This enables an application to talk to another application across the network based entirely on the socket number. The sending and receiving machines maintain a port table that lists all active port numbers. The two machines involved have reversed entries for each session between the two, a process called binding. In other words, if one machine has the source port number 23 and the destination port number set at 25, then the other machine will have its source port number set at 25 and the destination port number set at 23.

Socket Programming Read the rest of this entry »