Passion of IT


These libraries allow to work with the lowest layer of the TCP-IP protocol in client-server applications, this layer is a little up the transport one.


Internet is a wide network, when a computer is connected to the telephone line, this machine is connected to the ISP (internet service provider) and this ISP have all the tools to allows to interconnect it to the internet.

When you digit your computer performs the following steps

  • digit press enter
  • your browser sends an http request of type get to the URL (uniform resource locator)
  • this request is converted in electromagnetic wave and it is sent to the cable
  • this request goes to DNS (Domain name system) distributed database that converts alias name to ip-address, for example on port 80 (standard http port)
  • your computer sends an http get request to an address, this request is a simple http message that arrives to the host that is connected to yours. this host “decide” at which port forwarding the message (at this port is connected another computer) according to its MAC address (Media access control) the address of the network board
  • The message reaches the first router and is forwarded to another subnetwork using IP Address
  • the message go through a lot of computers, switches, routers before reaching google because for example the client may be located in Italy and the server in UK)
  • at the end the message arrives to the server that answers it and then the answer packet comes back o the client

There are a lot of steps that are necessary to perform to allow the packet to arrive to the server.

For these reasons it is necessary that there is a structure composed by a lot of hierarchic layers and for these layers are known the interfaces. Each layer offers services at the upper layer using the interfaces of the lower layer.

These layers from up to downside are the following:

  • Application: the application in your PC: internet explorer or chrome (browser,  client HTTP), filezilla (client FTP) microsoft outlook (client SMTP-POP) etc
  • Middleware (it is not a real layer, it is contained in the application layer but for my description I split it from application layer): it is the layer that allows the client and the server to ignore the problem of communication: the client call a method of the middleware and this method call the server and vice-versa. For this reason it allows to communicate software written in different languages.  An example is ejb,spring beans, rmi, rest services etc. The client calls with his smartphone a web service, this application sends a soap request to the server, the visual studio application receives these request written in SOAP (XML) and sends the response
  • Transport layer: is the first layer that communicates with the destination (server), the address of this protocol is the port number, this number identifies that the application runs on the pc (for example there are two browsers connected to google, one is connected to, the other to, and the server can distinguish both requests ) this layer offers two services:
    • TCP (transmission control protocol): reliable way sends all packets in order and if any packet is corrupted is sends again
    • UDP (User datagram protocol): fast way if any packet (called datagram) doesn’t arrive to destination, it is lost because for example in a real time video or in a real time telephone call (VOIP) it is not necessary that everything arrives to the destination but is important the low latency
  • Network layer the address is IP, this level allows the packet to arrive to the server, this layer calculates the route for sending the packet to the destination, the devices that performs these operations are the routers
  • Network interface: this level is the responsible for the communication from one host to the other that is interconnected to it. this layer checks that the message arrives in order and not corrupted. The address of this layer is MAC, the devices that works to this level are switch and bridge. Switch and bridge don’t know IP address of the destination, the only way to send the packet to the destination is using the mac address. The service that convert ip address in MAC is ARP (Address Resolution Protocol). This layer also converts the message in electromagnetic wave and send it to the transport (for example antenna or cable).

The libraries work on the low part of middleware layer, over the transport layer.

For example your browser communicates with the server web via HTTP protocol that have a standard set of instructions, if you want to create your personal protocol to communicate with other computer, for example for making your peer to peer/VOIP distributed application you can use the libraries

These libraries allow computer programmer to choose the type of the message to send to the server: either TCP or UDP.

When you work with web services you use always TCP protocol and you send always XML message to the server, you cannot modify these parameters middleware, but if you know the socket libs you can create all type of web application.

 My Example

Screenshot from 2014-07-05 20:57:04The server has a simple demon multithreading application that listens on local machine to the port number inserted in input

the client has two parameters port number and server address, when you don’t insert the second one, the default address is localhost.

The server is always on and when you activate the client the server answer it. The message is a simple greeting.

click here to download the file

to use it


java -jar socketServer.jar <port_number>

java -jar socketClient.jar <port_number> <ip_or_alias_of_server>


java -jar socketServer.jar 4567

java -jar socketClient.jar 4567 localhost



No Comments Yet

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite="
"> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Recent Comments

Michele Rizzithe website doesn't exist. Ara you a robot? In any case it's difficult that an automatic system writes a comment here since there are two captchas...
Hello there! This is kind of off topic but I need some guidance from an established blog. Is it very hard to set up your own blog? I'm not very t...
We are a group of volunteers and opening a new scheme in our community. Your web site offered us with valuable information to work on. You've done a...
September 2021
« Jan