Syd
unread,Apr 7, 2011, 12:04:42 PM4/7/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ns-3-users
Hi Everyone,
I am attempting to have 2 clients (n0, n1) connect
to a server(n2) using UDP sockets. From the code below, I do the
following:
1. create 2 client sockets
2. create 1 server socket
3. send a packet from n0 to the server
4. send a packet from n1 to the server
Problem: n0 is successfully able to send a packet to the server and
receive a reply but n1 is unable to send a packet to the server (as a
simple test, if I schedule n0 to send a packet at 2 different times,
that works just fine). However, there are no build errors.
Questions:
1.) Do I need to specify a number of connections that the server
should "listen" to or am I overlooking some other component in UDP
socket creation?
2.) Is there any limitation on the number of sockets I create?
Cheers!
Sydney
/* n0---------n2----------n1 */
Ptr<Socket> srcSocket[2]; /* 2 client sockets */
Ptr<Socket> dstSocket; /* 1 server socket */
/* Create 2 client sockets */
for (int i=0; i< 2; i++)
{
srcSocket[i] = Socket::CreateSocket (nodes.Get(i),
TypeId::LookupByName ("ns3::UdpSocketFactory"));
srcSocket[i]->Bind ();
srcSocket[i]->SetRecvCallback (MakeCallback
(&NS3ElectricalModel::srcSocketRecv, this));
}
/* Create server socket */
dstSocket = Socket::CreateSocket (nodes.Get(2), TypeId::LookupByName
("ns3::UdpSocketFactory"));
uint16_t dstport = 12345;
dstaddr="10.1.1.2";
InetSocketAddress dst = InetSocketAddress (dstaddr, dstport);
dstSocket->Bind (dst);
dstSocket->SetRecvCallback (MakeCallback
(&NS3ElectricalModel::dstSocketRecv, this));
/* n0 sends packet to server */
Simulator::Schedule (Seconds (0.1),&NS3ElectricalModel::SendStuff,
this, srcSocket[0], dstaddr, dstport);
/* n1 sends packet to server */
Simulator::Schedule (Seconds (0.2),&NS3ElectricalModel::SendStuff,
this, srcSocket[1], dstaddr, dstport);