Unix Programming - Bind several ports to one socket

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > June 2007 > Bind several ports to one socket





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Bind several ports to one socket
Spoon

2007-06-22, 1:23 pm

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.
Spoon

2007-06-22, 1:23 pm

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 |
|------------------------------------/-------------------------------------|
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com