How to destroy a Socket object

495 views
Skip to first unread message

Brutus

unread,
Jan 2, 2013, 5:22:37 PM1/2/13
to ns-3-...@googlegroups.com
Hello guys!
I'm using NS3 in order to simulate a particular scenario in which a client receive a big file from a server. The communication use the TCP protocol in a particular way: instead of sending the file on a single TCP connection, the two nodes use a new TCP connection (on a different port) every X bytes.
 
For example (just to be more clear), if the file length is 1000 bytes and X is set to 10, the server sends the first 10 bytes on the port 8080, then sends the second 10 bytes on the port 8081, and so on...
 
Now my problem is that with big files, when the scenario require more than 16384 connections, the simulation gets an ERRNO = 12 (Cannot allocate memory) and NS3 is no longer able to create new sockets.
 
I enabled logging for the TCPSocket class and noticed that all the socket  objects are destroyed at the end of the simulation and not when the Socket->Close() function is invoked. Is it right or is it expected to destroy the socket immediately?
And if NS3 destroys all the sockets at the end of the simulation by default, is there a way of forcing it to destroy them immediately? Or can i configure it to use more space and avoid ERRNO 12?
 
Thank you very much for your help.

ron

unread,
Apr 16, 2015, 5:54:03 AM4/16/15
to ns-3-...@googlegroups.com
Hi, did you get resolve the socket problem?

 

Tommaso Pecorella

unread,
Apr 16, 2015, 7:13:26 AM4/16/15
to ns-3-...@googlegroups.com
Hi,

sockets are not meant to be destroyed by the user. The best suggestion is to close them and reutilize the socket itself (open it again).

Cheers,

T.

bor...@gmail.com

unread,
Apr 8, 2017, 5:31:09 PM4/8/17
to ns-3-users
Hi Tommaso,

I have same problem, when I am binding a socket. After execution of many socket bind command, simulator  is giving  ERRNO = 12 (Cannot allocate memory). I have my own application, I have a large topology and I am sending lots of packet thru the TCP sockets. For each packet send operation, I am creating a socket,  binding it. And then I am sending packet and then closing related  socket. 

Is "socket->close()" command clear/free socket from memory?

To observe the effect of "socket->close()"  command in my code, I deleted that command and rerun the code. Result did not change, at the same time and at the same node gave same error. How can I remove unused socket from memory?

Thank you very much for your help.

16 Nisan 2015 Perşembe 14:13:26 UTC+3 tarihinde Tommaso Pecorella yazdı:

bor...@gmail.com

unread,
Apr 8, 2017, 5:57:52 PM4/8/17
to ns-3-users
I am sorry, in my question, I had forgotten to write connect command after bind command. I am creating a socket,  binding and connecting it. And then I am sending packet and then closing related  socket.

9 Nisan 2017 Pazar 00:31:09 UTC+3 tarihinde bor...@gmail.com yazdı:

Tommaso Pecorella

unread,
Apr 21, 2017, 6:09:54 PM4/21/17
to ns-3-users
Hi,

no, the socket is not cleared immediately from memory. Especially in the TCP case, sockets need to wait the effective connection close, which happens after 3 minutes. If you open a lot of sockets in the meantime, you can have issues.
The problem is another one: do you really need to create another socket (answer: no, you can reuse the old one).

T. 

bor...@gmail.com

unread,
Apr 24, 2017, 3:22:26 AM4/24/17
to ns-3-users

Hello Tommaso,

Thank you very much for your answer, I understood the source of problem. I  need to parallel packet sending, so I have to use multiple port. And some packets has priority, they must not wait on queue. You are right, as a result I have to manage sockets..

Thanks again,  Vedat.

22 Nisan 2017 Cumartesi 01:09:54 UTC+3 tarihinde Tommaso Pecorella yazdı:

richard

unread,
Sep 23, 2017, 7:16:12 PM9/23/17
to ns-3-users
Hi Thomaso, 

I ran into the same problem. And I don't really understand what is the way of fixing it that you propose. How do you reuse sockets ? 
Reply all
Reply to author
Forward
0 new messages