How to send user-defined data as a packet?

238 views
Skip to first unread message

HHicker

unread,
Mar 6, 2015, 4:51:18 PM3/6/15
to ns-3-...@googlegroups.com
Hi I'm new in NS3. Right now I kinda have gone through all materials in tutorial but I'm wondering how to send some specific data in the packet? I found some function like:
Ptr<Socket> sock = ...;
sock->Send (Buffer ("hello", 5));

But honestly I don't know how to use it correctly. 

Therefore, my first question will be how to send this kind data in NS3? My second question is what's the next step for me to learn NS3? I try to read some module codes but when I try to use some functions there always be some errors.

Tommaso Pecorella

unread,
Mar 7, 2015, 1:08:35 AM3/7/15
to ns-3-...@googlegroups.com
Hi,

the correct way is to create a Packet with the content you want to send, then to send it. An example is in rc/applications/model/ping6.cc:
  data[0] = 0xDE;
  data
[1] = 0xAD;
  data
[2] = 0xBE;
  data
[3] = 0xEF;


  p
= Create<Packet> (data, 4);

The packet will contain the data 0xDEAD 0xBEEF (they're hexadecimal numbers).

Hope this helps,

T.
Reply all
Reply to author
Forward
0 new messages