Re: [gnet] Problems with GNet and GIOChannels...



On Wed, 2004-08-25 at 21:26, James Wiggs wrote:
>    Thanks for your feedback on this.  I've implemented a solution based
> on GServer/GConn as you and Tim both suggested.  I'm running into some
> problems with it that have me more or less stumped.  There's one basic
> question that I never even *thought* to ask, but perhaps I should.  All
> of the example codes in the GNet distribution deal solely with ASCII
> character data.  Can the sockets maintained by GNet handle *BINARY*
> data or can they not?  I need to be able to pass any kind of data into
> these sockets and have it come back out again at the other end, intact,
> without killing my code in the process.

For what it's worth, I transmit binary data (the actually format of the
data is ASN.1, which is a binary packing format) all the time through a
GConn * socket.  So no, there's no inherent ASCII-only factor here.  The
only catch is that socket traffic is not guaranteed to come all at once
in distinct messages.  Sometimes you get 5 bytes, sometimes just 1. 
That's why all data protocols include a header with a length field so
you know exactly how many bytes to wait for (you have to keep looping on
a read until you get them all).  Not sure that this has anything to do
with your problem, though.

Michael

> 
>    That said, I have some code snippets to pass along to see if anyone
> can spot something obviously wrong.  Here's some structure definitions:
> 
> typedef struct _ServerProcess {
> 	gchar			Name[32];
> 	GInetAddr		*IpAddr;
> 	gint			Port;
> 	GServer			*Server;
> 	GServerFunc		(*ConnFunc)();
> 	GThread			*Thread;
> 	GAsyncQueue		*Queue;
> 	GMainContext	*Context;
> 	GMainLoop		*MainLoop;
> 	GTree			*ClientTree;
> 	GMutex			*ClientTreeMutex;
> 	gint			ref_count;
> } ServerProcess;
> 
> typedef struct _ClientProcess {
> 	gchar			Name[32];
> 	GInetAddr		*IpAddr;
> 	gint			Port;
> 	guint			UniqueID;
> 	gint			PermOrTemp;
> 	gint			IncomingOrOutgoing;
> 	ServerProcess	*ServerProc;
> 	GServer			*Server;
> 	GConn			*Connect;
> 	GConnFunc		(*CallbackFunc)();
> 	GThread			*Thread;
> 	GAsyncQueue 	*Queue;
> 	GMainContext 	*Context;
> 	GMainLoop		*MainLoop;
> 	GQueue			*IncomingData;
> 	GQueue			*OutgoingData;
> 	gint			waitingForMessage;
> 	gint			waitingForPayload;
> 	gint			waitingForHeader;
> 	NetworkMessage	*IncomingMessage;
> 	gint			ref_count;
> } ClientProcess;
> 
> 
> typedef struct _NetworkMessageHeader {
> 	guchar			SOHByte;
> 	guchar			HeaderSizeByte;
> 	NetworkMsgType	MsgType;
> 	gsize			MsgSize;
> 	guint			UniqueID;
> 	guchar			EOHByte1;
> 	guchar			EOHByte2;
> } NetworkMessageHeader;
> 
> 
> typedef struct _NetworkMessage {
> 	guchar			SOHByte;
> 	guchar			HeaderSizeByte;
> 	NetworkMsgType	MsgType;
> 	gsize			MsgSize;
> 	guint			UniqueID;
> 	guchar			EOHByte1;
> 	guchar			EOHByte2;
> 	gpointer		MsgData;
> } NetworkMessage;
> 
> _______________________________________________
> gnet mailing list
> gnet lists gnetlibrary org
> http://lists.gnetlibrary.org/mailman/listinfo/gnet




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