Re: Glib::IOChannel in sockets... (2)



On Mon, 21 Dec 2009 16:36:57 -0500
José Alburquerque <jaalburquerque cox net> wrote:

> On Mon, 2009-12-21 at 18:42 +0100, Glus Xof wrote: 
> > Hello guys,
> > 
> > Some days ago, I wrote,
> > 
> > 2009/12/17 Glus Xof <gtglus gmail com>:
> > > Hello guys,
> > >
> > > I was unsuccessfully googling, searching for an explanations
> > > about how to use Glib::IOChannel in case of Sockets: a little
> > > tutorial, or a code example...
> > 
> > and I truly need to communicate two proceses running in different
> > machines (by sockets), both sending & receiving Glib::ustring
> > values. For the moment, using socket(), bind(), listen(), accept(),
> > connect()... is enough to interchange std::string values, but I get
> > "Glib::ConvertError"s with Glib::ustring.
> 
> Maybe setting the encoding would make a difference.
> 
> The following excerpt from the Glib::IOChannel docs[1] seems relevant:
> 
> "Note that IOChannels implement an automatic implicit character set
> conversion to the data stream, and usually will not pass by default
> binary data unchanged. To set the encoding of the channel, use e.g.
> set_encoding("ISO-8859-15"). To set the channel to no encoding, use
> set_encoding() without any arguments."

Note also that if you are sending UTF-8 over the socket you have no
right to assume that a read on the socket will always produce a whole
character (UTF-8 characters can be between 1 and 5 bytes long).  If you
are not doing a read delimited by, say, line ends, you will need to
reassemble your UTF-8.

If you want some ideas here is a class that will do that for you:
http://cxx-gtk-utils.cvs.sourceforge.net/viewvc/*checkout*/cxx-gtk-utils/c%2B%2B-gtk-utils/c%2B%2B-gtk-utils/reassembler.h
http://cxx-gtk-utils.cvs.sourceforge.net/viewvc/*checkout*/cxx-gtk-utils/c%2B%2B-gtk-utils/c%2B%2B-gtk-utils/reassembler.cpp

Chris


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