Discussion:
[asio-users] Use multiple UDP sockets bound to same local server port
Gheorghe Marinca
2012-09-03 20:29:50 UTC
Permalink
Hy.

I've been looking for some days for a resolution to this.
Is it possible to bind multiple sockets to same UDP server port ? If I use :

socket(ioService,
boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port))

and if I try to create another socket on same port (used for sending
datagrams from same server port *but* to different clients endpoint) I get
bind errors (asio throws exception)
Is there a way to do this ? This must be a common use case, sending
datagrams to multiple clients using same server port...

Thanks
-Ghita
Jeff Koftinoff
2012-09-03 20:34:28 UTC
Permalink
Hello Ghita

You are not to use different sockets for this purpose.

You are not to use bind for sending to a client.

You are to use send_to() with the existing server socket. One of the parameters of send_to() is the address of the client you are sending to.

Remember that if you are using async_send_to() you can not call it again on the same socket until the first async_send_to() was signalled as completed.

Regards,
Jeff
Post by Gheorghe Marinca
Hy.
I've been looking for some days for a resolution to this.
socket(ioService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port))
and if I try to create another socket on same port (used for sending datagrams from same server port *but* to different clients endpoint) I get bind errors (asio throws exception)
Is there a way to do this ? This must be a common use case, sending datagrams to multiple clients using same server port...
Thanks
-Ghita
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Gheorghe Marinca
2012-09-03 20:50:08 UTC
Permalink
Thanks for prompt replay Jeff. I see that normal UDP API could use option
"reuse port" but ASIO only has

boost::asio::socket_base::reuse_address

The problem with the approach mentioned by you is that in this case on
multiple clients requests (and time needed on each one for processing)
I cannot simultaneously "async_receive_from" (for reading more
requests),
and "async_send_to" (for sending back responses as they are
available). How I am going to have scalability ?

Best regards
-Ghita
Post by Jeff Koftinoff
Hello Ghita
You are not to use different sockets for this purpose.
You are not to use bind for sending to a client.
You are to use send_to() with the existing server socket. One of the
parameters of send_to() is the address of the client you are sending to.
Remember that if you are using async_send_to() you can not call it again
on the same socket until the first async_send_to() was signalled as
completed.
Regards,
Jeff
Hy.
I've been looking for some days for a resolution to this.
socket(ioService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port))
and if I try to create another socket on same port (used for sending
datagrams from same server port *but* to different clients endpoint) I get
bind errors (asio throws exception)
Is there a way to do this ? This must be a common use case, sending
datagrams to multiple clients using same server port...
Thanks
-Ghita
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats.
http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Jeff Koftinoff
2012-09-03 20:59:51 UTC
Permalink
"reuse port" and "reuse address" are not useful in this situation and are not used for this purpose.

A single async_receive_from call will receive from any client. The callback will tell you the address of the sender.

A single async_send_to call will send to any client.

Yes you may have only one pending at a time, but this is what you need to use a queue for.

Regards,
Jeff
Thanks for prompt replay Jeff. I see that normal UDP API could use option "reuse port" but ASIO only has
boost::asio::socket_base::reuse_address
The problem with the approach mentioned by you is that in this case on multiple clients requests (and time needed on each one for processing) I cannot simultaneously "async_receive_from" (for reading more requests),
and "async_send_to" (for sending back responses as they are available). How I am going to have scalability ?
Best regards
-Ghita
Hello Ghita
You are not to use different sockets for this purpose.
You are not to use bind for sending to a client.
You are to use send_to() with the existing server socket. One of the parameters of send_to() is the address of the client you are sending to.
Remember that if you are using async_send_to() you can not call it again on the same socket until the first async_send_to() was signalled as completed.
Regards,
Jeff
Post by Gheorghe Marinca
Hy.
I've been looking for some days for a resolution to this.
socket(ioService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port))
and if I try to create another socket on same port (used for sending datagrams from same server port *but* to different clients endpoint) I get bind errors (asio throws exception)
Is there a way to do this ? This must be a common use case, sending datagrams to multiple clients using same server port...
Thanks
-Ghita
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Gheorghe Marinca
2012-09-03 21:16:24 UTC
Permalink
I saw at some point a suggestion that I may use multiple ioservice threads
for scalability. Is there a way to use same udp socket on multiple threads
for achieving that?
Post by Jeff Koftinoff
"reuse port" and "reuse address" are not useful in this situation and are
not used for this purpose.
A single async_receive_from call will receive from any client. The
callback will tell you the address of the sender.
A single async_send_to call will send to any client.
Yes you may have only one pending at a time, but this is what you need to use a queue for.
Regards,
Jeff
Thanks for prompt replay Jeff. I see that normal UDP API could use option
"reuse port" but ASIO only has
boost::asio::socket_base::reuse_address
The problem with the approach mentioned by you is that in this case on multiple clients requests (and time needed on each one for processing) I cannot simultaneously "async_receive_from" (for reading more requests),
and "async_send_to" (for sending back responses as they are available). How I am going to have scalability ?
Best regards
-Ghita
Post by Jeff Koftinoff
Hello Ghita
You are not to use different sockets for this purpose.
You are not to use bind for sending to a client.
You are to use send_to() with the existing server socket. One of the
parameters of send_to() is the address of the client you are sending to.
Remember that if you are using async_send_to() you can not call it again
on the same socket until the first async_send_to() was signalled as
completed.
Regards,
Jeff
Hy.
I've been looking for some days for a resolution to this.
socket(ioService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port))
and if I try to create another socket on same port (used for sending
datagrams from same server port *but* to different clients endpoint) I get
bind errors (asio throws exception)
Is there a way to do this ? This must be a common use case, sending
datagrams to multiple clients using same server port...
Thanks
-Ghita
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats.
http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats.
http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Jeff Koftinoff
2012-09-03 21:41:08 UTC
Permalink
The asio example "HTTP Server 2" at http://www.boost.org/doc/libs/1_51_0/doc/html/boost_asio/examples.html
shows how to make a server with one io_service per CPU..

Remember that with your UDP server, a client's request may come in on any thread.

How long will the processing take for each incoming message? An alternate solution is to make a queue of requests and responses and dispatch the requests to a pool of worker threads.

Regards,
Jeff
I saw at some point a suggestion that I may use multiple ioservice threads for scalability. Is there a way to use same udp socket on multiple threads for achieving that?
"reuse port" and "reuse address" are not useful in this situation and are not used for this purpose.
A single async_receive_from call will receive from any client. The callback will tell you the address of the sender.
A single async_send_to call will send to any client.
Yes you may have only one pending at a time, but this is what you need to use a queue for.
Regards,
Jeff
Thanks for prompt replay Jeff. I see that normal UDP API could use option "reuse port" but ASIO only has
boost::asio::socket_base::reuse_address
The problem with the approach mentioned by you is that in this case on multiple clients requests (and time needed on each one for processing) I cannot simultaneously "async_receive_from" (for reading more requests),
and "async_send_to" (for sending back responses as they are available). How I am going to have scalability ?
Best regards
-Ghita
Hello Ghita
You are not to use different sockets for this purpose.
You are not to use bind for sending to a client.
You are to use send_to() with the existing server socket. One of the parameters of send_to() is the address of the client you are sending to.
Remember that if you are using async_send_to() you can not call it again on the same socket until the first async_send_to() was signalled as completed.
Regards,
Jeff
Post by Gheorghe Marinca
Hy.
I've been looking for some days for a resolution to this.
socket(ioService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port))
and if I try to create another socket on same port (used for sending datagrams from same server port *but* to different clients endpoint) I get bind errors (asio throws exception)
Is there a way to do this ? This must be a common use case, sending datagrams to multiple clients using same server port...
Thanks
-Ghita
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Gheorghe Marinca
2012-09-03 21:47:27 UTC
Permalink
Thanks I'll have a look on that. Processing takes variable time because
it's io bound also. When using multiple threads I guess I use same server
send/receive socket but it will receive 'events' in different threads?
Post by Jeff Koftinoff
The asio example "HTTP Server 2" at
http://www.boost.org/doc/libs/1_51_0/doc/html/boost_asio/examples.html
shows how to make a server with one io_service per CPU..
Remember that with your UDP server, a client's request may come in on any thread.
How long will the processing take for each incoming message? An alternate
solution is to make a queue of requests and responses and dispatch the
requests to a pool of worker threads.
Regards,
Jeff
I saw at some point a suggestion that I may use multiple ioservice threads
for scalability. Is there a way to use same udp socket on multiple threads
for achieving that?
Post by Jeff Koftinoff
"reuse port" and "reuse address" are not useful in this situation and are
not used for this purpose.
A single async_receive_from call will receive from any client. The
callback will tell you the address of the sender.
A single async_send_to call will send to any client.
Yes you may have only one pending at a time, but this is what you need to
use a queue for.
Regards,
Jeff
Thanks for prompt replay Jeff. I see that normal UDP API could use option
"reuse port" but ASIO only has
boost::asio::socket_base::reuse_address
The problem with the approach mentioned by you is that in this case on multiple clients requests (and time needed on each one for processing) I cannot simultaneously "async_receive_from" (for reading more requests),
and "async_send_to" (for sending back responses as they are available). How I am going to have scalability ?
Best regards
-Ghita
Post by Jeff Koftinoff
Hello Ghita
You are not to use different sockets for this purpose.
You are not to use bind for sending to a client.
You are to use send_to() with the existing server socket. One of the
parameters of send_to() is the address of the client you are sending to.
Remember that if you are using async_send_to() you can not call it again
on the same socket until the first async_send_to() was signalled as
completed.
Regards,
Jeff
Hy.
I've been looking for some days for a resolution to this.
socket(ioService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port))
and if I try to create another socket on same port (used for sending
datagrams from same server port *but* to different clients endpoint) I get
bind errors (asio throws exception)
Is there a way to do this ? This must be a common use case, sending
datagrams to multiple clients using same server port...
Thanks
-Ghita
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats.
http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats.
http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats.
http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Yuri Timenkov
2012-09-04 03:45:05 UTC
Permalink
2 sockets open with the same port (with reuse port/address option) may
receive only broad/multicast packets. Unicast packet will be delivered to
only one (usually last opened) socket.

There is no such thing as "connection" for UDP. When you "connect" your udp
socket you just set up a filter or default send_to address. But from
network perspective you still have a single open port. You can receive and
send packets from/to any address.

I think you also misunderstand what receive_from does. The endpoint
parameter is *output-only*. ASIO puts origin of received packet there and
doesn't use it for input.

As it was said many times in this list you should store this address/port
combination in your own, user-space "session" and send response there later
(when you receive your data) using async_send_to.

I really don't understand why are you so concerned about scalability? Have
you done any measurements? Web servers have only 1 socket open (on 80 port)
and at the same time can handle lots of requests each second. It's not
sockets you should worry about.
How multiple sockets help you? In rough approximation you still have single
network interface, single packets queue in OS kernel. Even if you send data
to "different" sockets then packets still have to be put into single queue.
If your handler is I/O-bound you should make it async to scale well.

Regards,
Yuri

On Tue, Sep 4, 2012 at 12:50 AM, Gheorghe Marinca <
Post by Gheorghe Marinca
Thanks for prompt replay Jeff. I see that normal UDP API could use option
"reuse port" but ASIO only has
boost::asio::socket_base::reuse_address
The problem with the approach mentioned by you is that in this case on multiple clients requests (and time needed on each one for processing) I cannot simultaneously "async_receive_from" (for reading more requests),
and "async_send_to" (for sending back responses as they are available). How I am going to have scalability ?
Best regards
-Ghita
Post by Jeff Koftinoff
Hello Ghita
You are not to use different sockets for this purpose.
You are not to use bind for sending to a client.
You are to use send_to() with the existing server socket. One of the
parameters of send_to() is the address of the client you are sending to.
Remember that if you are using async_send_to() you can not call it again
on the same socket until the first async_send_to() was signalled as
completed.
Regards,
Jeff
Hy.
I've been looking for some days for a resolution to this.
socket(ioService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port))
and if I try to create another socket on same port (used for sending
datagrams from same server port *but* to different clients endpoint) I get
bind errors (asio throws exception)
Is there a way to do this ? This must be a common use case, sending
datagrams to multiple clients using same server port...
Thanks
-Ghita
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats.
http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Gheorghe Marinca
2012-09-04 04:31:14 UTC
Permalink
Well in case of tcp you have connections and when you accept communication
with a client happens on a newly created client server socket. In case of
udp that is a shared socket instance I cannot concurrently use same socket
for multiple send receive with multiple clients. So I would said that
decently that can affect scalability if I don't use multiple ioservice
threads as was suggested at some point.
Post by Yuri Timenkov
2 sockets open with the same port (with reuse port/address option) may
receive only broad/multicast packets. Unicast packet will be delivered to
only one (usually last opened) socket.
There is no such thing as "connection" for UDP. When you "connect" your
udp socket you just set up a filter or default send_to address. But from
network perspective you still have a single open port. You can receive and
send packets from/to any address.
I think you also misunderstand what receive_from does. The endpoint
parameter is *output-only*. ASIO puts origin of received packet there and
doesn't use it for input.
As it was said many times in this list you should store this address/port
combination in your own, user-space "session" and send response there later
(when you receive your data) using async_send_to.
I really don't understand why are you so concerned about scalability? Have
you done any measurements? Web servers have only 1 socket open (on 80 port)
and at the same time can handle lots of requests each second. It's not
sockets you should worry about.
How multiple sockets help you? In rough approximation you still have
single network interface, single packets queue in OS kernel. Even if you
send data to "different" sockets then packets still have to be put into
single queue. If your handler is I/O-bound you should make it async to
scale well.
Regards,
Yuri
On Tue, Sep 4, 2012 at 12:50 AM, Gheorghe Marinca <
Post by Gheorghe Marinca
Thanks for prompt replay Jeff. I see that normal UDP API could use option
"reuse port" but ASIO only has
boost::asio::socket_base::reuse_address
The problem with the approach mentioned by you is that in this case on multiple clients requests (and time needed on each one for processing) I cannot simultaneously "async_receive_from" (for reading more requests),
and "async_send_to" (for sending back responses as they are available). How I am going to have scalability ?
Best regards
-Ghita
Post by Jeff Koftinoff
Hello Ghita
You are not to use different sockets for this purpose.
You are not to use bind for sending to a client.
You are to use send_to() with the existing server socket. One of the
parameters of send_to() is the address of the client you are sending to.
Remember that if you are using async_send_to() you can not call it again
on the same socket until the first async_send_to() was signalled as
completed.
Regards,
Jeff
Hy.
I've been looking for some days for a resolution to this.
socket(ioService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port))
and if I try to create another socket on same port (used for sending
datagrams from same server port *but* to different clients endpoint) I get
bind errors (asio throws exception)
Is there a way to do this ? This must be a common use case, sending
datagrams to multiple clients using same server port...
Thanks
-Ghita
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats.
http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Alejandro Santos
2012-09-04 04:57:18 UTC
Permalink
You don't need multiple io_services. You can either:

a) Run many threads from the same io_service, each thread calling
io_service::run() as per HTTP Server example 3,

b) Use one thread to read UDP data and implement your own
producer/consumer scheme using good ol' pool of threads.


On Tue, Sep 4, 2012 at 1:31 AM, Gheorghe Marinca
Post by Gheorghe Marinca
Well in case of tcp you have connections and when you accept communication
with a client happens on a newly created client server socket. In case of
udp that is a shared socket instance I cannot concurrently use same socket
for multiple send receive with multiple clients. So I would said that
decently that can affect scalability if I don't use multiple ioservice
threads as was suggested at some point.
Post by Yuri Timenkov
2 sockets open with the same port (with reuse port/address option) may
receive only broad/multicast packets. Unicast packet will be delivered to
only one (usually last opened) socket.
There is no such thing as "connection" for UDP. When you "connect" your
udp socket you just set up a filter or default send_to address. But from
network perspective you still have a single open port. You can receive and
send packets from/to any address.
I think you also misunderstand what receive_from does. The endpoint
parameter is *output-only*. ASIO puts origin of received packet there and
doesn't use it for input.
As it was said many times in this list you should store this address/port
combination in your own, user-space "session" and send response there later
(when you receive your data) using async_send_to.
I really don't understand why are you so concerned about scalability? Have
you done any measurements? Web servers have only 1 socket open (on 80 port)
and at the same time can handle lots of requests each second. It's not
sockets you should worry about.
How multiple sockets help you? In rough approximation you still have
single network interface, single packets queue in OS kernel. Even if you
send data to "different" sockets then packets still have to be put into
single queue. If your handler is I/O-bound you should make it async to scale
well.
Regards,
Yuri
On Tue, Sep 4, 2012 at 12:50 AM, Gheorghe Marinca
Post by Gheorghe Marinca
Thanks for prompt replay Jeff. I see that normal UDP API could use option
"reuse port" but ASIO only has
boost::asio::socket_base::reuse_address
The problem with the approach mentioned by you is that in this case on
multiple clients requests (and time needed on each one for processing) I
cannot simultaneously "async_receive_from" (for reading more requests),
and "async_send_to" (for sending back responses as they are available).
How I am going to have scalability ?
Best regards
-Ghita
Post by Jeff Koftinoff
Hello Ghita
You are not to use different sockets for this purpose.
You are not to use bind for sending to a client.
You are to use send_to() with the existing server socket. One of the
parameters of send_to() is the address of the client you are sending to.
Remember that if you are using async_send_to() you can not call it again
on the same socket until the first async_send_to() was signalled as
completed.
Regards,
Jeff
Hy.
I've been looking for some days for a resolution to this.
socket(ioService,
boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port))
and if I try to create another socket on same port (used for sending
datagrams from same server port *but* to different clients endpoint) I get
bind errors (asio throws exception)
Is there a way to do this ? This must be a common use case, sending
datagrams to multiple clients using same server port...
Thanks
-Ghita
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats.
http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
--
Alejandro Santos
Yuri Timenkov
2012-09-04 06:21:36 UTC
Permalink
This post might be inappropriate. Click to display it.
Gheorghe Marinca
2012-09-04 08:28:20 UTC
Permalink
I can use the same udp socket for multiple sens/received is just that I
have to synchronize calling send/receive even though I communicate at some
point with different client endpoints (using same udp socket). But this has
already been discussed. Thanks for inputs to you all.
Post by Yuri Timenkov
1) "Listen" tcp sockets. A SYN packet with unknown source address/port
arrives here.
2) "Connected" tcp sockets. They differ from the former in way that they
also have remote address and port. Thus when packet arrives OS dispatches
it appropriately. Besides this dispatching OS also reassembles packets into
bytes stream, performs flow control and re-requests lost packets.
3) UDP sockets. There is no connection here. Packet can arrive and be sent
to any address/port at any time. If you need a "connection" or a "session"
you have to group packets by originating address/port yourself. ASIO kindly
provides you this information by receive_from function.
What makes you think you can't use same socket for multiple sends and
receives?
On Tue, Sep 4, 2012 at 8:31 AM, Gheorghe Marinca <
Post by Gheorghe Marinca
Well in case of tcp you have connections and when you accept
communication with a client happens on a newly created client server
socket. In case of udp that is a shared socket instance I cannot
concurrently use same socket for multiple send receive with multiple
clients. So I would said that decently that can affect scalability if I
don't use multiple ioservice threads as was suggested at some point.
Post by Yuri Timenkov
2 sockets open with the same port (with reuse port/address option) may
receive only broad/multicast packets. Unicast packet will be delivered to
only one (usually last opened) socket.
There is no such thing as "connection" for UDP. When you "connect" your
udp socket you just set up a filter or default send_to address. But from
network perspective you still have a single open port. You can receive and
send packets from/to any address.
I think you also misunderstand what receive_from does. The endpoint
parameter is *output-only*. ASIO puts origin of received packet there and
doesn't use it for input.
As it was said many times in this list you should store this
address/port combination in your own, user-space "session" and send
response there later (when you receive your data) using async_send_to.
I really don't understand why are you so concerned about scalability?
Have you done any measurements? Web servers have only 1 socket open (on 80
port) and at the same time can handle lots of requests each second. It's
not sockets you should worry about.
How multiple sockets help you? In rough approximation you still have
single network interface, single packets queue in OS kernel. Even if you
send data to "different" sockets then packets still have to be put into
single queue. If your handler is I/O-bound you should make it async to
scale well.
Regards,
Yuri
On Tue, Sep 4, 2012 at 12:50 AM, Gheorghe Marinca <
Post by Gheorghe Marinca
Thanks for prompt replay Jeff. I see that normal UDP API could use
option "reuse port" but ASIO only has
boost::asio::socket_base::reuse_address
The problem with the approach mentioned by you is that in this case on multiple clients requests (and time needed on each one for processing) I cannot simultaneously "async_receive_from" (for reading more requests),
and "async_send_to" (for sending back responses as they are available). How I am going to have scalability ?
Best regards
-Ghita
Post by Jeff Koftinoff
Hello Ghita
You are not to use different sockets for this purpose.
You are not to use bind for sending to a client.
You are to use send_to() with the existing server socket. One of the
parameters of send_to() is the address of the client you are sending to.
Remember that if you are using async_send_to() you can not call it
again on the same socket until the first async_send_to() was signalled as
completed.
Regards,
Jeff
On 2012-09-03, at 1:29 PM, Gheorghe Marinca <
Hy.
I've been looking for some days for a resolution to this.
socket(ioService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port))
and if I try to create another socket on same port (used for sending
datagrams from same server port *but* to different clients endpoint) I get
bind errors (asio throws exception)
Is there a way to do this ? This must be a common use case, sending
datagrams to multiple clients using same server port...
Thanks
-Ghita
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats.
http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Yuri Timenkov
2012-09-05 04:15:40 UTC
Permalink
On the second thought if you really need different sockets you may clone
one (by WSADuplicateSocket/dup). There is native() function which returns
descriptor and you can then pass cloned descriptor to assign().

I expect it would be quite safe to send data to them simultaneously, but
it's better to avoid reading from clones.

On Tue, Sep 4, 2012 at 12:28 PM, Gheorghe Marinca <
Post by Gheorghe Marinca
I can use the same udp socket for multiple sens/received is just that I
have to synchronize calling send/receive even though I communicate at some
point with different client endpoints (using same udp socket). But this has
already been discussed. Thanks for inputs to you all.
Post by Yuri Timenkov
1) "Listen" tcp sockets. A SYN packet with unknown source address/port
arrives here.
2) "Connected" tcp sockets. They differ from the former in way that they
also have remote address and port. Thus when packet arrives OS dispatches
it appropriately. Besides this dispatching OS also reassembles packets into
bytes stream, performs flow control and re-requests lost packets.
3) UDP sockets. There is no connection here. Packet can arrive and be
sent to any address/port at any time. If you need a "connection" or a
"session" you have to group packets by originating address/port yourself.
ASIO kindly provides you this information by receive_from function.
What makes you think you can't use same socket for multiple sends and
receives?
On Tue, Sep 4, 2012 at 8:31 AM, Gheorghe Marinca <
Post by Gheorghe Marinca
Well in case of tcp you have connections and when you accept
communication with a client happens on a newly created client server
socket. In case of udp that is a shared socket instance I cannot
concurrently use same socket for multiple send receive with multiple
clients. So I would said that decently that can affect scalability if I
don't use multiple ioservice threads as was suggested at some point.
Post by Yuri Timenkov
2 sockets open with the same port (with reuse port/address option) may
receive only broad/multicast packets. Unicast packet will be delivered to
only one (usually last opened) socket.
There is no such thing as "connection" for UDP. When you "connect" your
udp socket you just set up a filter or default send_to address. But from
network perspective you still have a single open port. You can receive and
send packets from/to any address.
I think you also misunderstand what receive_from does. The endpoint
parameter is *output-only*. ASIO puts origin of received packet there and
doesn't use it for input.
As it was said many times in this list you should store this
address/port combination in your own, user-space "session" and send
response there later (when you receive your data) using async_send_to.
I really don't understand why are you so concerned about scalability?
Have you done any measurements? Web servers have only 1 socket open (on 80
port) and at the same time can handle lots of requests each second. It's
not sockets you should worry about.
How multiple sockets help you? In rough approximation you still have
single network interface, single packets queue in OS kernel. Even if you
send data to "different" sockets then packets still have to be put into
single queue. If your handler is I/O-bound you should make it async to
scale well.
Regards,
Yuri
On Tue, Sep 4, 2012 at 12:50 AM, Gheorghe Marinca <
Post by Gheorghe Marinca
Thanks for prompt replay Jeff. I see that normal UDP API could use
option "reuse port" but ASIO only has
boost::asio::socket_base::reuse_address
The problem with the approach mentioned by you is that in this case on multiple clients requests (and time needed on each one for processing) I cannot simultaneously "async_receive_from" (for reading more requests),
and "async_send_to" (for sending back responses as they are available). How I am going to have scalability ?
Best regards
-Ghita
Post by Jeff Koftinoff
Hello Ghita
You are not to use different sockets for this purpose.
You are not to use bind for sending to a client.
You are to use send_to() with the existing server socket. One of the
parameters of send_to() is the address of the client you are sending to.
Remember that if you are using async_send_to() you can not call it
again on the same socket until the first async_send_to() was signalled as
completed.
Regards,
Jeff
On 2012-09-03, at 1:29 PM, Gheorghe Marinca <
Hy.
I've been looking for some days for a resolution to this.
socket(ioService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port))
and if I try to create another socket on same port (used for sending
datagrams from same server port *but* to different clients endpoint) I get
bind errors (asio throws exception)
Is there a way to do this ? This must be a common use case, sending
datagrams to multiple clients using same server port...
Thanks
-Ghita
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats.
http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Gheorghe Marinca
2012-09-05 13:56:36 UTC
Permalink
I haven't managed to use WSADuplicateSocket on windows. And I think that
you are supposed to use this only if you want to duplicate/clone a port on
a different process but I might be wrong.
Post by Yuri Timenkov
On the second thought if you really need different sockets you may clone
one (by WSADuplicateSocket/dup). There is native() function which returns
descriptor and you can then pass cloned descriptor to assign().
I expect it would be quite safe to send data to them simultaneously, but
it's better to avoid reading from clones.
On Tue, Sep 4, 2012 at 12:28 PM, Gheorghe Marinca <
Post by Gheorghe Marinca
I can use the same udp socket for multiple sens/received is just that I
have to synchronize calling send/receive even though I communicate at some
point with different client endpoints (using same udp socket). But this has
already been discussed. Thanks for inputs to you all.
Post by Yuri Timenkov
1) "Listen" tcp sockets. A SYN packet with unknown source address/port
arrives here.
2) "Connected" tcp sockets. They differ from the former in way that they
also have remote address and port. Thus when packet arrives OS dispatches
it appropriately. Besides this dispatching OS also reassembles packets into
bytes stream, performs flow control and re-requests lost packets.
3) UDP sockets. There is no connection here. Packet can arrive and be
sent to any address/port at any time. If you need a "connection" or a
"session" you have to group packets by originating address/port yourself.
ASIO kindly provides you this information by receive_from function.
What makes you think you can't use same socket for multiple sends and
receives?
On Tue, Sep 4, 2012 at 8:31 AM, Gheorghe Marinca <
Post by Gheorghe Marinca
Well in case of tcp you have connections and when you accept
communication with a client happens on a newly created client server
socket. In case of udp that is a shared socket instance I cannot
concurrently use same socket for multiple send receive with multiple
clients. So I would said that decently that can affect scalability if I
don't use multiple ioservice threads as was suggested at some point.
Post by Yuri Timenkov
2 sockets open with the same port (with reuse port/address option) may
receive only broad/multicast packets. Unicast packet will be delivered to
only one (usually last opened) socket.
There is no such thing as "connection" for UDP. When you "connect"
your udp socket you just set up a filter or default send_to address. But
from network perspective you still have a single open port. You can receive
and send packets from/to any address.
I think you also misunderstand what receive_from does. The endpoint
parameter is *output-only*. ASIO puts origin of received packet there and
doesn't use it for input.
As it was said many times in this list you should store this
address/port combination in your own, user-space "session" and send
response there later (when you receive your data) using async_send_to.
I really don't understand why are you so concerned about scalability?
Have you done any measurements? Web servers have only 1 socket open (on 80
port) and at the same time can handle lots of requests each second. It's
not sockets you should worry about.
How multiple sockets help you? In rough approximation you still have
single network interface, single packets queue in OS kernel. Even if you
send data to "different" sockets then packets still have to be put into
single queue. If your handler is I/O-bound you should make it async to
scale well.
Regards,
Yuri
On Tue, Sep 4, 2012 at 12:50 AM, Gheorghe Marinca <
Post by Gheorghe Marinca
Thanks for prompt replay Jeff. I see that normal UDP API could use
option "reuse port" but ASIO only has
boost::asio::socket_base::reuse_address
The problem with the approach mentioned by you is that in this case on multiple clients requests (and time needed on each one for processing) I cannot simultaneously "async_receive_from" (for reading more requests),
and "async_send_to" (for sending back responses as they are available). How I am going to have scalability ?
Best regards
-Ghita
On Mon, Sep 3, 2012 at 11:34 PM, Jeff Koftinoff <
Post by Jeff Koftinoff
Hello Ghita
You are not to use different sockets for this purpose.
You are not to use bind for sending to a client.
You are to use send_to() with the existing server socket. One of the
parameters of send_to() is the address of the client you are sending to.
Remember that if you are using async_send_to() you can not call it
again on the same socket until the first async_send_to() was signalled as
completed.
Regards,
Jeff
On 2012-09-03, at 1:29 PM, Gheorghe Marinca <
Hy.
I've been looking for some days for a resolution to this.
socket(ioService, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port))
and if I try to create another socket on same port (used for sending
datagrams from same server port *but* to different clients endpoint) I get
bind errors (asio throws exception)
Is there a way to do this ? This must be a common use case, sending
datagrams to multiple clients using same server port...
Thanks
-Ghita
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats.
http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
asio-users mailing list
https://lists.sourceforge.net/lists/listinfo/asio-users
_______________________________________________
Using Asio? List your project at
http://think-async.com/Asio/WhoIsUsingAsio
Loading...