Re: [gnet-devel] GIOChannels



Thanks very much. For some reason it's always the simplest solutions that I don't see (ie. just sending a string directly to the client iochannel). I had solved my problem with pipes (sort of... pipe() doesn't seem to work very well on windows >_<), but this solution seems to make much more sense. Thanks again.

On Sun, Aug 17, 2008 at 7:47 AM, Tim-Philipp Müller <t i m zen co uk> wrote:
On Fri, 2008-08-08 at 11:58 -0700, n duarte wrote:

Hi,

sorry for the late reply.

> I suppose that I all I should have said was that i need to know how to
> have a GIOChannel read from a text widget instead of stdin. Hope this
> clears up what I previously said.

Your code is a bit messy and hard to read (at least to me), so I can
only guess what you're trying to do.

I don't understand why you are creating the server_iochannel at all if
you don't want to read from stdin. You don't need that iochannel to send
text over a client connection. (And g_io_channel_init is not a function
you'll ever need btw).

Here's how I think you want things to happen:
 - create a tcp socket server (as you do)
 - start accepting connections async, provide a callback function
 - run a main loop
 - now, when a client connects to the server, your async_accept
  function will be called, which will give you the GTcpSocket *
  of the client which just connected
 - from the client GTcpSocket you can then get the GIOChannel
  and watch for data sent by the client via the main loop via
  g_io_add_watch(), similar to what you've done already
 - to send data, just use g_io_channel_write_chars() and pass
  the string from your text entry

Hope this helps (the GConn/GServer API might be a bit easier if you want
async networking)

Cheers
 -Tim





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]