This is the first Network lesson.
We will see differents notions to understand how a computer can communicates with another through internet, a local network ...
All these notions will be very usefull to understand the
network tutorials.
A computer is identified, on a network or on the web, by his IP Internet Protocol address
(Network layer). An IP is unique, it is used as an identifier.
An IP address (IPv4) is constituted by 4 octets.
It is commonly represented by or value separated by points :
X.X.X.X
An octet is composed of 8 bits, so each number is between 0 and 2^8-1 = 255 (included).
Example of an IP address : 159.182.10.3
Note 1:
127.0.0.1 is a particular IP address : it represents the localhost
(ie the computer in which the programm is running). Usefull for local testing.
255.255.255.255 represent all computer (used
for broadcast ie send the same information
to all computers of the same network).
Note 2:
IPv6 are represented by 6 octets.
It will replace IPv4 in the close futur to compensate for the lack of IP
address.
There is a way to know easily if you can recognize a computer.
Use the ping command. If you receive packets, the IP address can be recognize.
Here is an example to contact localhost :
Ping command
Two computer communicates using a specific Protocol
(Transport layer).
There is two different protocol used for the transmission of the data between
two computers :
TCP Transmission Control Protocol
UDP User Datagram Protocol
These two protocols are differents in a lot of points. Due to their differents characteristics, their are used for specific applications.
TCP is a reliable transmission. This protocol ensure you that
all packets sented arrived at destination, in the same order of sending.
The addressee send an acknowledgement of receipt to the sender, to inform the
packet is well arrived and he can send the next one.
A packet is a piece of data (datas are divited in small pieces). It contain the
data sended and other informations like IP address &
MAC address of the sender and he addressee,
communication port, crc (redundance control), ... A packet give the
information of who have sended the packet, who should receive it & which
application/service should use it.
In contraste to TCP, UDP does not ensure that the data sent are arrived and in the same order of sending.
The addressee does not send any acknowledgement of receipt. For this, UDP is faster than TCP
(less data flow for transmit the same information).
For this protocol, datas send are called datagram.
To communicate with another computer, all the datas flows through a single cable (Transmission
layer). For exemple, the RJ45 cable of your
network card).
Data received can have differents destination on your computer. For exemple, you received data of
an internet page in the same time that your chat programm. The first data is for your internet browser
application, the second if for you're chat programm.
Communication ports are used to direct
datas to its associated programm (Application layer).
It is a 16 bits number (value is between 0 to 2^16-1 = 65535).
The 1024 first port are reserved by the system. Each of them correspond to a
specific service :
Port 21 : FTP (File Transfer Protocol)
Port 23 : Telnet
Port 25 : Courriel
Port 80 : HTTP (Hyper Text Transfer Protocol)
Port 119 : Usenet
...
Communication port
A communication port can be used for a single connection. So, a single
service/application can connect to a port and a single service/application can
listen on a port.
We have seen before how to recognize a computer in a network/internet and how to recognize the data received.
Now, we will see how two computers communicates.
A socket is used to make a connection between two computer. A socket is an
endpoint, two sockets are needed to make the link (one on the server side, one
on the client side).
A socket is bounded on a specific communication port. All the data flows throw
this connection start or end on a socket. So, for sending/receiving datas,
just write/read on the socket.
When two computers communicates, one or more are clients and one
should be the server.
The client and the server runs generaly in two differents computers.But, they can be
on the same computer (commonly for local test).
The server listening on a specific communication port, using a particular socket (ServerSocket).
When a client want to connects him, he send a connection request to the server (1). The client need to know the IP address (or the name) of the server and the
communication port (see above).
If the server accepts the connection, he creates a connection between him and
the client. A new socket (Socket) is created on the client and on the server.
A new socket is created on the server to listen for other connection (multiple
connection of clients).
Note :
When the connection is made, the server uses another communication port to
communicates with the client.
This is represented in the following picture for the case of an http request :
HTTP Request example
Note :
3802 and 5243 ports are given for exemple, it can be any ports from 1024 to the
maximum (see Communication Port).
When the connection is created, the client and the server can communicates. To
communicates, they should know which "language" they uses
(communication protocol). This is essential to know how
to interpret datas received.
, but you can creates your own protocol for you application purpose.
We will use a particular communication protocol in
Tutorial 2. We should write the server and the client because it is a
particular communication protocol.
In Tutorial 3, we will implement HTTP
requests to write a basic HTTP server (server side). Here we will only write
the server end. Client end is not necessary because we can use any internet
browser to communicates with the server. Effectively, all internet browser
know the HTTP request (defined by standard rules).
The server provides services. Clients uses services provided by the server.
I will show you few examples of client/server applications below.
A multiplayer game is typically a client/server application.
There are an host of the game (the server) and players that join the game (clients).
The game is owned by the server.
The server receive all players informations, he bring together all game
information (player position ...). Then, he send these informations to all
player for the new state of the game (new player position).
All people connects themselves to a server.
The server can communicates with all clients. He can informs a client to who are
connected and not.
Each clients can only communicates with the server, they need to inform the
server for which the data is. The server forward the data to its addressee.
With this mechanism, all clients connected to the server can communicates between them.
Other mechanism can be used to create a chat application.
Last modified on 01/07/2010 | |
Copyright © 2004-2010 Jérôme JOUVIE - All rights reserved. | http://jerome.jouvie.free.fr/ |