Re: what's problem in GIOChannel ?
- From: Martyn Russell <ginxd btopenworld com>
- To: "chen.shengqi" <chen shengqi connet com tw>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: what's problem in GIOChannel ?
- Date: Fri, 27 Sep 2002 19:06:24 +0100
chen.shengqi wrote:
dear sirs:
I use following code to connect to 192.141.140.2:9999, when read data,recvbytes is 28( include data in
first packet and 2bytes in second packet ) and ret=1, then recvbytes always return 0,and ret=0, but server
should send serval packet, first packet is 26bytes,and following packet is large than 26 bytes, total are
large then 1024 bytes. If I use telnet connect to the port, telnet can receive data correctly. How should I
use GIOChannel?
thanks.
int swarefd=-1;
GIOChannel *SwareSocketChannel=NULL;
void
on_open1_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
printf("open now\n");
swarefd = connect_to_sware("192.141.140.6",9999);
if (swarefd<0) { printf("connect_to_sware failed\n"); return; }
printf("connect_to_sware ok swarefd=%d\n",swarefd);
SwareSocketChannel = g_io_channel_unix_new(swarefd);
if (SwareSocketChannel==NULL) { printf("g_io_channel_unix_new failed \n"); return; }
printf("g_io_channel_unix_new ok \n");
g_io_add_watch(SwareSocketChannel, G_IO_IN | G_IO_PRI | G_IO_HUP, read_data_from_socket,NULL);
printf("g_io_add_watch ok \n");
return;
}
/* read data on socket */
gboolean read_data_from_socket(GIOChannel *source, GIOCondition condition, gpointer data)
{
gchar recvbuf[2048];
GError *err=NULL;
GIOStatus ret;
int recvbytes=0;
ret=g_io_channel_read_chars(source, recvbuf,2048,&recvbytes,&err);
printf("condition=%d,read return %d, recvbytes=%d\n",condition,ret,recvbytes);
if (recvbytes>0) debug_hex("read_data_from_socket",recvbuf,recvbytes,1);
return TRUE;
}
????^介e??fj)b? b藏-??iu朕?X?? ???+?m???j)`???????ē????+-?w棹dj?]z鳐?+-
Might I suggest you use gtk_input_add. It is better at handling sockets
than g_io_channel. (unless your application is completely GLIB based and
includes NO GTK, but if that was the case you wouldnt be on this list
right!).
Regards,
Martyn
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]