Network App 2024
Network App 2024
1. Application Description
Chat messaging applications require an instant messaging protocol that allows for (near)real-
time communication between clients. Both sender and receiver must follow the same ap-
plication protocol. Some of the well known protocols include WebRTC, WebSocket, and
IRC - Internet Relay Chat. Most of these protocols work by establishing peer-to-peer
connections between client applications; this means messages are sent directly between
two devices without going through a server. However, in some cases, a server may still
be involved for tasks such as signaling and initialising/facilitating the establishment of
the peer-to-peer connections.
In this assignment, you are to design and implement a peer-to-per chat application
that makes use of both UDP and TCP sockets – UDP for transmitting real-time media
streams; TCP for signaling and initializing peer communication. A server is needed to
coordinate initial client connections, and clients should be able to query the server for
lists of available clients, and to obtain parameters for the establishment of communication
between clients.
You should implement your client to use a TCP connection to interact with server.
The client implementation should allow for command line arguments, such as specifying
the server IP address, the port at which the server is listening, and the request, e.g to
sign-up or announce connection parameters. Clients may also want to request a list of
1
available peers, or communication parameters of a particular peer. Servers needs to have
means for maintaining a list of active peer clients.
2
2. A report (max 6 pages) on the design and functionality of your chat application
(individual sections on the client implementation).
4. Oral presentation to be scheduled with the TAs and Tutors (oral to be done on
day after submission deadline)
3
A. Multi-threaded Client/Server Applications—Sockets
Programming
A.1. What is a socket?
A socket is the one end-point of a two-way communication link between two programs
running over the network. Running over the network means that the programs run on
different computers, usually referred as the local and the remote computers. However
one can run the two programs on the same computer. Such communicating programs
constitutes a client/server application. The server implements a dedicated logic, called
service. The clients connect to the server to get served, for example, to obtain some
data or to ask for the computation of some data. Different client/server applications
implement different kind of services.
To distinguish different services, a numbering convention was proposed. This con-
vention uses integer numbers, called port numbers, to denote the services. A server
implementing a service assigns a specific port number to the entry point of the service.
There are no specific physical entry points for the services in a computer. The port num-
bers for services are stored in configuration files and are used by the computer software
to create network connections.
A socked is a complex data structure that contains an internet address and a port
number. A socket, however, is referenced by its descriptor, like a file which is referenced
by a file descriptor. That is why, the sockets are accessed via an application programming
interface (API) similar to the file input/output API. This makes the programming of
network applications very simple. The two-way communication link between the two
programs running on different computers is done by reading from and writing to the
sockets created on these computers. The data read from a socked is the data wrote
into the other socket of the link. And reciprocally, the the data wrote into a socket
in the data read from the other socket of the link. These two sockets are created and
linked during the connection creation phase. The link between two sockets is like a
pipe that is implemented using a stack of protocols. This linking of the sockets involves
that internally a socket has a much more complex data structure, or more precisely, a
collaboration of data structures. Thus, a socket data structure is more than just an
internet address and a port number. You have to imagine a socket as a data structure
that contains at least the internet address and the port number on the local computer,
and the internet address and the port number on the remote computer.
4
clients. It can not use this specific port for data communication with the clients because
the server must be able to accept the client connection at any instant. So, its specific
port is dedicated only to listening for new connection requests. The server side socket
associated with specific port is called server socket. When a connection request arrives
on this socket from the client side, the client and the server establish a connection. This
connection is established as follows:
1. When the server receives a connection request on its specific server port, it creates
a new socket for it and binds a port number to it.
2. It sends the new port number to the client to inform it that the connection is
established.
The server communicates with the client by reading from and writing to the new port.
If other connection requests arrive, the server accepts them in the similar way creating
a new port for each new connection. Thus, at any instant, the server must be able
to communicate simultaneously with many clients and to wait on the same time for
incoming requests on its specific server port. The communication with each client is
done via the sockets created for each communication.
TCP is a connection-oriented protocol. In order to communicate over the TCP proto-
col, a connection must first be established between two sockets. While one of the sockets
listens for a connection request (server), the other asks for a connection (client). Once
the two sockets are connected, they can be used to transmit and/or to receive data.
When we say ”two sockets are connected” we mean the fact that the server accepted a
connection. As it was explained above the server creates a new local socket for the new
connection. The process of the new local socket creation, however, is transparent for the
client.
The datagram communication protocol, known as UDP (user datagram protocol), is a
connectionless protocol. No connection is established before sending the data. The data
are sent in a packet called datagram. The datagram is sent like a request for establishing
a connection. However, the datagram contains not only the addresses, it contains the
user data also. Once it arrives to the destination the user data are read by the remote
application and no connection is established. This protocol requires that each time a
datagram is sent, the local socket and the remote socket addresses must also be sent in
the datagram. These addresses are sent in each datagram.