TCP-client-server application

449 views
Skip to first unread message

Md Ashiqur Rahman

unread,
Nov 6, 2017, 10:01:40 PM11/6/17
to ns-3-users
Hello. I'm trying to create a TCP client server application where I have the following simple topology:

C<--------->S

Client sends the start signal to server (e.g. a string- "Send" as payload.). Upon receiving, the server continuously sends TCP bytestream to client (more like an FTP server but no fixed file size) until connection is lost by some way (e.g. client IP change).

How can I achieve this? The provided examples on TCP and FTP are all mentioning the sender just starts sending packets (without any client initiation).

Tommaso Pecorella

unread,
Nov 7, 2017, 8:52:56 AM11/7/17
to ns-3-users
Hi,

you can do it by easily modifying the UdpEcho applications.
Simply modify the receive part of the server to avoid the echo and to send a continuous stream of data.
Practically it's a mix of UdpEcho and BulkSend. It should be fairly doable.

T.

Md Ashiqur Rahman

unread,
Nov 11, 2017, 3:32:07 PM11/11/17
to ns-3-users
Hi, I tried to simply replicate the UdpEcho application but changing the typeIDs as Tcp to check first if I can exchange packets as tcp instead of udp:

TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory");

to

TypeId tid = TypeId::LookupByName ("ns3::TcpSocketFactory");

However, I see no packets being exchanged. What could be wrong here? 

Regards-
Ashiq

Tommaso Pecorella

unread,
Nov 11, 2017, 6:55:01 PM11/11/17
to ns-3-users
Hi,

well, it's not THAT simple. Study the TCP applications, like PacketSink and OnOffApplication to see how TCP works.

T.

Md Ashiqur Rahman

unread,
Nov 16, 2017, 3:06:14 PM11/16/17
to ns-3-users
Thanks Tommaso,

That helped, and now I have a client-serve TCP connection where client initiates connection by sending a very small packet and then Server sends TCP bytestream to client. However, I used Ptr<Socket> in client side instead of application.

The next question is, if my client changes IP at runtime say from 10.1.1.1 to 10.1.1.3 and initiates the connection again (Server IP = 10.1.1.2), the reconnection works. but if I switch from 10.1.1.3 to 10.1.1.1 again after receiving the large file for the second time, I get to see TCP port reuse in the pcap file and don't receive the large file for the third time in the client.

How can i enable port reuse in ns3 Ptr<Socket> like that SO_REUSEADDR, or SO_REUSEPORT done with setsockopt?

Regards-
Ashiq

Tommaso Pecorella

unread,
Nov 16, 2017, 9:26:12 PM11/16/17
to ns-3-users
Hi Ashiq,

that's a kinda strange behaviour. It is also possible that you found a bug.
Can you share the script ?

Thanks,

T.

Md Ashiqur Rahman

unread,
Nov 21, 2017, 2:07:30 PM11/21/17
to ns-3-users
Hello Tommaso,


I converted to using client sockets in an application of my own as I am using two clients here to confirm that the router is serving two clients simultaneously.

You can find the usage in the Readme file.

Regards-
Ashiq

Tommaso Pecorella

unread,
Nov 22, 2017, 5:54:23 PM11/22/17
to ns-3-users
Hi Ashiq,

the "problem" isn't really a problem. You can't delete an IP interface if it's in use. Or better, the TCP protocol isn't built in a way to be safe against interface deletion while a connection is up.
In your second case the connection is still up, as the Tx buffer isn't yet empty.
In ns-3-dev it even give a segmentation fault...

Hope this helps,

T.

Md Ashiqur Rahman

unread,
Nov 27, 2017, 2:27:47 PM11/27/17
to ns-3-users
Hello Tommaso,

This really helps. However, isn't this a common scenario that a link might suddenly break WHILE nodes are exchanging data? i.e. connection still up?

In wireless scenario, a STATION might go out of access point's range at any time while data still transmitting or connection still up. How do I handle this? Also, what would be the proper way of changing IP at runtime regardless of connection up or close? And what would be a good way to handle this IP change event if the connection is still up?

Regards-
Ashiq

Tommaso Pecorella

unread,
Nov 27, 2017, 6:23:38 PM11/27/17
to ns-3-users
In a common scenario the link doesn't break. It goes down, your TCP connection fails for timeouts and you start a new communication only when the link is up again.
In the common scenario you don't change the IP number manually, it's changed by DHCP (yes, DHCP is available in ns-3). When the link is up again, your application will start sending data again, eventually after some swearing by the user.

About how to handle this, there's a pending enhancement request to link the linkup / link down at MAC layer with the interface up/down at IP layer, but it's still to be done.
If you want to contribute, enhancements are always welcome.

T.

chintan patel

unread,
Dec 27, 2017, 1:16:06 AM12/27/17
to ns-3-users
Hello,

I am doing PhD in IoT Security and for the implementation of topology i want to make 5 clients and 1 server. so can you please help me how to make topology in NS3?

Tommaso Pecorella

unread,
Dec 27, 2017, 8:24:31 AM12/27/17
to ns-3-users
Hi,

just follow the tutorial and read the TCP examples, these should point you in the right direction.

T.
Reply all
Reply to author
Forward
0 new messages