Re: [gnet-devel] IOChannels



On Mon, 30 Jun 2008, n duarte wrote:

> Although i have seen examples where data sent to a GIOChannel from stdin, a
> problem I have come across has stumped me. Is it possible to have a gchar*
> and send its data (as in a text string) to a GIOChannel in place of stdin?
> Much thanks to anyone that can help.

Hi Nate,

I'm pretty sure you should be able to send data out on a GIOChannel simply
using the gnet_io_channel_writen call.

For example, suppose you have a pointer "channel" to a GIOChannel, then you
could have something along the following lines:

  gchar * toSend = "A string to send";
  unsigned int amountToSend = strlen (toSend);
  unsigned int amountSent;
  GIOError error;

  error = gnet_io_channel_writen (channel, (gpointer)toSend, 
   amountToSend, & amountSend);

  if ((error != G_IO_ERROR_NONE) || (amountToSend != amountSent)) {
    printf ("An error occurred.\n");
  }

Note that this won't send the terminating null character on the end of your
string (to send the null terminator just add 1 to the amountToSend variable).
I'm afraid I've not tested the code above fully, but something along those
lines should work I think. There's more about this in the gnet documentation
here:

http://www.gnetlibrary.org/docs/gnet-iochannel.html

Hope this helps, and apologies if I misunderstood your question.

Regards,

David
-- 
Website: http://www.flypig.co.uk



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