what's problem in GIOChannel ?




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;
}




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