| Author |
Bind several ports to one socket
|
|
|
| Hello everyone,
Consider an app that expects UDP datagrams on two ports A and B.
Is it possible (in the sockets API) to create a single UDP socket that
will receive datagrams addressed either to port A or to port B?
Regards.
| |
| Maxim Yegorushkin 2007-06-22, 1:23 pm |
| On 22 Jun, 14:46, Spoon <root@localhost> wrote:
> Consider an app that expects UDP datagrams on two ports A and B.
>
> Is it possible (in the sockets API) to create a single UDP socket that
> will receive datagrams addressed either to port A or to port B?
No.
Are you having difficulty handling two sockets?
| |
| Christophe Leitienne 2007-06-22, 1:23 pm |
| Hi,
> Consider an app that expects UDP datagrams on two ports A and B.
>
> Is it possible (in the sockets API) to create a single UDP socket that
> will receive datagrams addressed either to port A or to port B?
Sorry that's not possible.
You must bind each UDP socket to its own port, and use a mechanism such
as select() on both socket to detect data availability.
Christophe.
| |
|
| Maxim Yegorushkin wrote:
> Spoon wrote:
>
>
> No.
>
> Are you having difficulty handling two sockets?
Hehe :-)
On the sending side, I can use a single socket to send to multiple end
points. I was looking for a symmetric approach on the receiving side.
| |
| Casper H.S. Dik 2007-06-22, 1:23 pm |
| Spoon <root@localhost> writes:
>Hello everyone,
>Consider an app that expects UDP datagrams on two ports A and B.
>Is it possible (in the sockets API) to create a single UDP socket that
>will receive datagrams addressed either to port A or to port B?
No. Use poll/select on the two sockets.
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
| |
| James Antill 2007-06-23, 1:37 am |
| On Fri, 22 Jun 2007 17:04:08 +0200, Spoon wrote:
> On the sending side, I can use a single socket to send to multiple end
> points. I was looking for a symmetric approach on the receiving side.
You mean sendto()? It's called recvfrom(). There is no function to
either send() or recv() from multiple local points though, which is
what you asked for.
--
James Antill -- james@and.org
C String APIs use too much memory? ustr: length, ref count, size and
read-only/fixed. Ave. 55% overhead over strdup(), for 0-20B strings
http://www.and.org/ustr/
| |
| phil-news-nospam@ipal.net 2007-06-23, 1:23 pm |
| On Fri, 22 Jun 2007 17:04:08 +0200 Spoon <root@localhost> wrote:
| Maxim Yegorushkin wrote:
|
|> Spoon wrote:
|>
|>> Consider an app that expects UDP datagrams on two ports A and B.
|>>
|>> Is it possible (in the sockets API) to create a single UDP socket that
|>> will receive datagrams addressed either to port A or to port B?
|>
|> No.
|>
|> Are you having difficulty handling two sockets?
|
| Hehe :-)
|
| On the sending side, I can use a single socket to send to multiple end
| points. I was looking for a symmetric approach on the receiving side.
If the application cannot be easily coded to handle poll/select on two or
more sockets, an option would be to fork a separate process to handle it
and pipe all the packets to the main application. If the child process
can't handle multiple sockets, either, then fork one for each.
--
|---------------------------------------/----------------------------------|
| Phil Howard KA9WGN (ka9wgn.ham.org) / Do not send to the address below |
| first name lower case at ipal.net / spamtrap-2007-06-23-1139@ipal.net |
|------------------------------------/-------------------------------------|
|
|
|
|