socket programming using python

Networking is an essential task in software applications nowadays.Python is a powerful language for network programming. Python support both low level and high level access to network services. At a low level, we can access the basic socket support in the underlying operating system, which allows you to implement clients and servers for both connection-oriented and connectionless protocols. Python has a socket module to support socket programming. Python also has libraries that provide higher-level access to specific application-level network protocols, such as FTP, HTTP, and so on.

The following are some of the key concepts in network programming.

Sockets
Sockets are the endpoints of a bidirectional communications channel. Sockets may communicate within a process, between processes on the same machine, or between processes on different continents.Sockets may be implemented over a number of different channel types: Unix domain sockets, TCP, UDP, and so on.
Then what is a port in a socket? A socket directs to a particular computer in a network. Once connection reaches on a computer it want to identify the application it can connect. Port’s are made for this purpose. In a computer there will be thousands of ports in it. first 1234 ports are reserved for system and rest of ports can be applied to user applications. Each port is assigned with an application and it waits for an application to connect.

TCP and UDP:
In order to transmit data between client and server in the internet we depend on TCP and UDP protocols. So what are them? and what is the difference between them?

TCP (Transmission Control Protocol) is a set of rules (protocol) used along with the Internet Protocol (IP) to send data in the form of message units between computers over the Internet. UDP is an alternative to TCP. But there is major difference between them in the case of data transmission.

More specifically TCP is connection oriented protocol. TCP provides reliable, ordered delivery of a stream of bytes from a program on one computer to another program on another computer. We use this protocol where we each byte of data is important. In the delivery of a email we would not like to miss any byte of data, situations like these where each byte of data is important, needs reliable transmission. TCP/IP are used in situation like these and it has proper error checking mechanism in the destination to ensure that all bytes of data is reached at the destination in order. Here the correctness is more important than delivery time.

But there are some other situations where we need data to be reached in the destination within some time constraint, here the correctness of data may be tolerated to some extend. For example in real time video streaming we need bytes of data with in its streaming time. In such application’s it is not important whether the data comes in order or data comes from the same server. we just need all data in time. Even if data reached the destination out of order it should have proper mechanism to rearrange the byte order, it also adjust the data lose to some extend. In such situation’s we depend on connection-less protocol such as UDP. Applications, which do not need reliable data stream service, may use the User Datagram Protocol (UDP), which provides a datagram service that emphasizes reduced latency over reliability.

I will come back with some examples in my next post…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s