Socket->Send() or Socket->SendTo(address)?

233 views
Skip to first unread message

Zhaodong Wang

unread,
Sep 3, 2020, 9:16:28 PM9/3/20
to ns-3-users
Hi everyone,

We have a question regarding the very basic usage of ns3::Socket. 

From this doc, seems like we should just use Send() all the time, SendTo(address) is not even mentioned in the API section.

However, we found that Send() and SendTo(address) are essentially the same for TCP (TcpSocketBase), but NOT the same for UDP (UdpSocketImpl). In fact, we found that, when using UDP, Send() doesn’t send anything and returns -1. But SendTo(address) works. This is very confusing. 

Could anyone help me check if I did anything wrong?

Thanks

Tom Henderson

unread,
Sep 4, 2020, 12:45:02 AM9/4/20
to ns-3-...@googlegroups.com, Zhaodong Wang
On 9/3/20 6:16 PM, Zhaodong Wang wrote:
Hi everyone,

We have a question regarding the very basic usage of ns3::Socket. 

From this doc, seems like we should just use Send() all the time, SendTo(address) is not even mentioned in the API section.

SendTo(address) is useful if you want to have a UDP socket that sends to multiple destinations.  In this case, you would not Connect the socket to any particular address, but instead use SendTo(address) each time.

If you previously called Connect() on the socket, it will set a default address and port so you can call Send() instead of SendTo (although you can still call SendTo if you prefer).


However, we found that Send() and SendTo(address) are essentially the same for TCP (TcpSocketBase), but NOT the same for UDP (UdpSocketImpl). In fact, we found that, when using UDP, Send() doesn’t send anything and returns -1. But SendTo(address) works. This is very confusing.


For TCP, you must always be connected to a single destination, so Send() and SendTo(address) should operate the same.

- Tom



Could anyone help me check if I did anything wrong?

Thanks
--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/0ad36468-f596-458d-99d5-1cb62a68356bn%40googlegroups.com.


Zhaodong Wang

unread,
Sep 4, 2020, 1:52:18 AM9/4/20
to ns-3-users
Hi Tom,

Thanks a lot for your clarification, this makes sense. I think it could be helpful if we have this in the ns3 wiki or at least in the comment of the SendTo() function for UdpSocketImpl? The current documentation seems pretty easy to get things wrong without knowing the reason from the error messages.

Best,
Zhaodong

Tom Henderson

unread,
Sep 7, 2020, 11:56:08 AM9/7/20
to ns-3-...@googlegroups.com, Zhaodong Wang
On 9/3/20 10:52 PM, Zhaodong Wang wrote:
> Hi Tom,
>
> Thanks a lot for your clarification, this makes sense. I think it
> could be helpful if we have this in the ns3 wiki or at least in the
> comment of the SendTo() function for UdpSocketImpl? The current
> documentation seems pretty easy to get things wrong without knowing
> the reason from the error messages.


Thanks for the documentation suggested; I have added a small section here:

https://www.nsnam.org/docs/models/html/sockets-api.html#use-of-send-vs-sendto

- tOM

Zhaodong Wang

unread,
Sep 17, 2020, 11:20:43 PM9/17/20
to ns-3-users
Awesome, thank you very much @Tom!
Reply all
Reply to author
Forward
0 new messages