On Fri, 2003-11-21 at 04:35, Mark Stevens wrote:
> Hi,
>
> I'm writing a UDP server which needs to listen to a number of ports that
> various clients send datagrams to. I'm trying to use g_io_add_watch()
> to register a callback which gets fired whenever there is something to
> read on any of the numerous ports. So I set up a GIOChannel for each of
> the ports and register it using g_io_add_watch().
>
> The problem I've encountered is that my callback only ever gets fired
> when data arrives at the *last* port that I register using
> g_io_add_watch(). I know for sure that data is being sent to all of the
> ports by my clients.
>
> As an example, I've included some code which does the same thing as my
> server is trying to do and which shows the problem.
>
> Is there something obvious I'm doing wrong?
>
> Thanks for any help or suggestions.
>
> Mark
You may want to take a look at libgnetwork on GNOME CVS, module
'libgnetwork', if you don't mind depending on GConf. There's a
GNetworkUdpDatagram object which handles this internally (so you can
treat the connections a objects which fire the "received" signal when
incoming data is received).
udp = g_object_new (GNETWORK_TYPE_UDP_DATAGRAM, "interface", NULL,
"port", port, NULL);
g_signal_connect (udp, "received", udp_received_cb, NULL);
/* get notification about the socket being closed & such. */
g_signal_connect (udp, "notify::status", udp_status_changed_cb, NULL);
gnetwork_datagram_open (udp);
udp2 = g_object_new (GNETWORK_TYPE_UDP_DATAGRAM, "interface", NULL,
"port", port2, NULL);
g_signal_connect (udp2, "received", udp_received_cb, NULL);
/* get notification about the socket being closed & such. */
g_signal_connect (udp2, "notify::status", udp_status_changed_cb, NULL);
gnetwork_datagram_open (udp2);
The only "extra" thing you need to remember to do is unref the objects
when you're done.
Up-to-the-build API docs are available at:
http://esco.mine.nu/gtk-doc/libgnetwork/
--
Peace,
Jim Cape
http://ignore-your.tv
"It is literally true that, like Christianity, Socialism
has conquered the world by defeating itself."
-- Alexander Berkman, ABC of Anarchism
This is a digitally signed message part