client-server udp socket sample code

880 views
Skip to first unread message

Kishore Kanala

unread,
Dec 22, 2015, 6:42:47 AM12/22/15
to ns-3-users
Hi,

    Can someone send me client-server UDP socket sample code in which application data (That is ns3 packet is sent and received) ? Please point me to a link where I can find it.
    Thanks in advance.

Regards,
Kishore

Konstantinos

unread,
Dec 22, 2015, 6:49:55 AM12/22/15
to ns-3-users
Hi Kishore,

Have you studied the ns-3 tutorial? 
Please go through that first. It should answer your question.

Regards,
Konstantinos

Tommaso Pecorella

unread,
Dec 22, 2015, 6:51:08 AM12/22/15
to ns-3-users
Hi,

what about looking under "examples/udp" and/or "examples/udp-client-server" ?

Please, read the tutorial and check the examples.

T.

Kishore Kanala

unread,
Dec 22, 2015, 8:00:31 AM12/22/15
to ns-3-users
Thanks a lot.
I do not see SetFill method for UdpClientHelper. How do I sent my own data in packet? Please note that data will change for each packet.
[I see SetFill for UdpEchoClientHelper]

Konstantinos

unread,
Dec 22, 2015, 8:16:05 AM12/22/15
to ns-3-users
Hi

The "helpers" are designed to "help" you interface with corresponding underlaid classes.
In this case the UdpClientHelper assists you to install and configure a UdpClient class.

There is no "SetFill" in that class because the developers did not think it was necessary for the purposes of the class.
Even in the UdpEchoClient the SetFill results in setting the content of the packets being the same. 

If you want to have an application that sends different data for each packet, you need to develop it.
Studying and understanding how SetFill is used in the UdpEchoClient, you can use a similar method in your own class to create new packets with your payload.

Regards,
K.

hellore...@gmail.com

unread,
May 25, 2016, 4:00:34 PM5/25/16
to ns-3-users
Hi

I am simulating Content Delivery Network. using above suggestion, i have implemented that client sends a page number to request to server (here server is dns server).

I want to implement that based on page number, server sends some IP address as a string.

how can i change payload of the packet at server end.

Regards
myprog5.cc

hellore...@gmail.com

unread,
May 29, 2016, 6:39:20 AM5/29/16
to ns-3-users
Hi

The above problem is solved by using:

void UdpEchoServer::HandleRead (Ptr<Socket> socket).

The payload of the packet can be changed before sending back the reply by UdpEchoServer i.e. write required code before these lines.

NS_LOG_LOGIC ("Echoing packet");
socket->SendTo (packet, 0, from);

Now please guide me that how the packet payload sent by server in reply can be used or displayed at client end.

Re

an05...@gmail.com

unread,
Apr 8, 2021, 7:44:49 AM4/8/21
to ns-3-users
Dear Konstantinos,
I am able to fill the string data in a packet sent from a client to a server.  But, I am facing a problem in the extraction of payload data (attached into  packet using SetFill()) at the server side.
Is there any method available to extract the data from the packet received at the UDP server? 
Reply all
Reply to author
Forward
0 new messages