tcp sockets
TRANSCRIPT
NETWORK
ARCHITECTURE 1
Project 1
By Chimmili Hari Kalyani (16212951) and Tanya
Srivastava (16211490)
Network Architecture
Project 1
By Chimmili Hari Kalyani and Tanya Srivastava
P a g e 1 | 12
1. Reviewed KR, P&D code and “UNIX Network Programming” by Stevens.
2. Obtained the source code for the client and server (posted below): simplex-
talk.c and simplex-talk-server.c. Make sure you can successfully compile
these programs using gcc. (Important: The code uses 5432 as the TCP port,
it is strongly suggested you choose a random port greater than 10000.)
Source code files are: SimpleClient.c, SimpleServer.c
Downloaded gcc (Cygwin) compiler and installed on my PC.
Chose TCP port# 55005
Compiled source code (both client and server)
3. Experiments with TCP sockets
Network Architecture
Project 1
By Chimmili Hari Kalyani and Tanya Srivastava
P a g e 2 | 12
a. Opened two terminals. Started one server in one terminal and one
client in another terminal (as shown in the below figure).
Sent message from the client to the server successfully (is shown in
the figure below).
b. While the first client is running, started nine other clients in the
background with their input redirected from SampleText.txt file.
Network Architecture
Project 1
By Chimmili Hari Kalyani and Tanya Srivastava
P a g e 3 | 12
c. Answer the following questions:
i. What happens to these ten clients?
Answer: The first 5 clients are blocked (excluding the first running
client) and those messages are not displayed on the server. The
client number 7, 8, 9 and 10 connections are refused.
ii. Do their connect()s fail, or time out, or succeed?
Answer: Connections are refused for the client number 7, 8, 9 and
10.
iii. Do any other calls block?
Answer: Yes, other than the first running client, the next five
client calls are blocked.
Network Architecture
Project 1
By Chimmili Hari Kalyani and Tanya Srivastava
P a g e 4 | 12
iv. Wait a bit, then make the first client exit. What happens?
Answer: After exiting the first client, there are 5 messages
displayed on the server terminal. Only the first 5 clients are able to
communicate to the server successfully.
d. Changed the server constant MAX PENDING to 1 and recompiled the
server source code.
e. Opened two terminals. Started one server in one terminal and one
client in another terminal. Able to send messages from the client to
the server. Left both the server and the client in running mode.
Network Architecture
Project 1
By Chimmili Hari Kalyani and Tanya Srivastava
P a g e 5 | 12
f. While the first client is running, started nine other clients in the
background with their input redirected from SampleText.txt file (as
shown in below).
g. Answer the following questions:
v. What happens to these ten clients?
Answer: The first client is blocked (excluding the first running client)
and the sampletext.txt message is not displayed on the server. The
other client (from 3 to 10) connections are refused.
vi. Do their connect()s fail, or time out, or succeed?
Answer: Connections are refused for the client number 3 to 10.
Network Architecture
Project 1
By Chimmili Hari Kalyani and Tanya Srivastava
P a g e 6 | 12
vii. Do any other calls block?
Answer: Yes, other than the first running client, the second client call
is blocked.
viii. Wait a bit, then make the first client exit. What happens?
Answer: After exiting the first client, the second client text message
displayed on the server terminal. Only the second client is able to
communicate to the server successfully.
h. NOTE: As we do not have a second PC – to perform this step.
Network Architecture
Project 1
By Chimmili Hari Kalyani and Tanya Srivastava
P a g e 7 | 12
We have used Hercules Utility Tool (running on my PC) in order to
mimic the second host.
Fig. Hercules utility tool
i. In Wireshark, under the Capture Options, entered tcp port 55005
as a capture filter and started as shown below.
Network Architecture
Project 1
By Chimmili Hari Kalyani and Tanya Srivastava
P a g e 8 | 12
j. Started Client on my PC (host) and typed several messages. And
typed one very long message without hitting enter, I quitted the Client
and stopped capture on Wireshark.
Because I could not run server and client on separate hosts ( I ran both
on the same host) – unfortunately, I could not capture any packets
using WireShark, with “tcp port 55005” as a filter.
Network Architecture
Project 1
By Chimmili Hari Kalyani and Tanya Srivastava
P a g e 9 | 12
k. Answer the following
i) How many packets were transmitted?
Answer: One packet
ii) What is the correspondence between messages and packets?
Answer: The long messages will be split into multiple packets of size
equal to ~1500 bytes, using TCP protocol.
l. Modified the client and server so that each time the client sends a
line to the server, the server sends the line back to the client (as shown
in figure below).
Network Architecture
Project 1
By Chimmili Hari Kalyani and Tanya Srivastava
P a g e 10 | 12
The client (and server) are now make alternating calls to recv() and send().
4. Experiments with UDP sockets
a) Modified the simplex-talk client and server source code to use UDP as the
transport protocol, rather than TCP. In both client and server, changed
SOCK STREAM to SOCK DGRAM.
b) In the client, removed the call to connect(). Used the sendto() syscall in the
place of the send() syscall.
c) In the server, removed the calls to listen() and accept(), and used a single
loop that calls recvfrom() with the sockets.
d) What happens when 2 or more clients connect to the same UDP server?
In UDP (stateless protocol), we have observed there is no issue when more
than 2 clients connected and no client is ever in the "connected" state.
Network Architecture
Project 1
By Chimmili Hari Kalyani and Tanya Srivastava
P a g e 11 | 12
Multiple clients are able to send packets to the same server, and their packets
arrived at the server (in random sequence).
e) How does this differ from TCP behavior?
We have observed that in TCP the messages sent from clients one after
the other (in order) and the messages received on the server is in the
same sequence (first send client message is received first).
In UDP, packets are sent individually. One packet per one read call.
In case of TCP, data is received as a “stream,” with nothing
distinguishing where one packet ends and another begins. There may
be multiple packets per read call.
In TCP, the long message sent from the multiple clients received
without lost or corrupted and all the messages are able to receive by the
server.
In case of UDP, the one very long message is not received correctly at
the server end (message received partially). The server did not receive
the long messages are sent from some of the clients, is shown in the
figure below.
Network Architecture
Project 1
By Chimmili Hari Kalyani and Tanya Srivastava
P a g e 12 | 12