All about programming in GNU/LINUX

Network Programming in GNU/LINUX:Importance of socket ports and Difference in coding of TCP and UDP socket applications

TCP and UDP are both transport layer protocols which involves process to process communication .As it is very important to identify the recipient device Locally or over Internet since

there will more than one computer in the network , it is equally important to identify right process in the receivers computer to which information has to be send since there will hundreds of processes running.

We’ll consider a practical scenario , Let us assume that users on system1 and system2 are communicating over INTERNET using 2 different programs , a Chat application and a VOIP based Application like SKYPE. The data sent from the Chat Application process from the system1 has to reach the chat application process running the system2 , not to any other process and it should follow he same in case of the VOIP application .The concept of software or logical ports help us identify the right process to receive the information across the network once the device is identified using its Network layer address(IP address) or data link layer address(MAC address).

 The concept of a network capable application or a process running on logical port ensures that the communication takes place between intended processes at the transport layer .

 TCP is connection oriented with many more checking mechanisms used to ensure message delivery and completeness , UDP has minimal checking, does not maintain a connection or ensure completeness or delivery of message.

TCP(Transmission Control Protocol). TCP is a connection-oriented protocol, a connection can be made from client to server, and from then on any data can be sent along that connection.

    • Reliable – when you send a message along a TCP socket, you know it will get there unless the connection fails completely. If it gets lost along the way, the server will re-request the lost part. This means complete integrity, things don’t get corrupted.

    • Ordered – if you send two messages along a connection, one after the other, you know the first message will get there first. You don’t have to worry about data arriving in the wrong order.

    • Heavyweight – when the low level parts of the TCP “stream” arrive in the wrong order, resend requests have to be sent, and all the out of sequence parts have to be put back together, so requires a bit of work to piece together.

  1. UDP(User Datagram Protocol). A simpler message-based connectionless protocol. With UDP you send messages(packets) across the network in chunks.

    • Unreliable – When you send a message, you don’t know if it’ll get there, it could get lost on the way.

    • Not ordered – If you send two messages out, you don’t know what order they’ll arrive in.

    • Lightweight – No ordering of messages, no tracking connections, etc. It’s just fire and forget! This means it’s a lot quicker, and the network card / OS have to do very little work to translate the data back from the packets.

 

While writing TCP based socket applications the connection has to be first established b/w the two process in the sender and reciever devices before any exchange of information could take place .the sequence of system calls involved in creating a TCP client/server program are as follows .

 Image

The connect call from the client establishes the connection b/w client and the server only after which the information exchange takes place .The following figure shows the sequence of calls involved in creating a TCP based Client/server application.

The following figure shows shows the sequence of calls involved in creating UDP based client/server application

 Image

 

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