Re: socket and gtk problem, help!



Instead of having a while, you could have a gtk_timeout with the timw you
think is Ok, 50 or 100ms in which you make your select, also with a timeout
(I'd say a lower one)
Or, as I do it myself and it worked fine so far, you could create a
GIOChannel (=g_io_channel_unix_new(socket)))
then add a watcher for this channel for G_IO_READ, and whatever you want,
and have your code doing something whenever you have "activity" on that
socket be execute in the watcher callback...
have a look at GIOChannel in the GLib reference
(developer.gnome.org->doc->API reference)

cheers...

Olivier.


On Wed, 2 Aug 2000, huangjnb@legend.com.cn wrote:
> Date: Wed, 2 Aug 2000 17:25:34 +0800
> To: gtk-devel-list@redhat.com, gnome-devel-list@gnome.org
> From: huangjnb@legend.com.cn
> Subject: socket and gtk problem, help!
> 
> 
> Hi,all, I am writing a server program which listen and process client's
> request from other computer on LAN. I build server's GUI with gtk and
> wrote a piece of code to listen socket request as follow: 
> 
> .... 
> BuildGUI(); 
> 
> do{ 
> int newsockd=accept(sockd,(struct sockaddr *)&client_addr,&sin_size); 
> if£¨newsockd!=-1£© 
>  DoSomething(); 
> else 
>  continue; 
> }while(1); 
> .... 
> 
> there, gtk_main(); was put in BuildGUI. The program suspend when it goes
> to gtk_main(), so the do-while loop does not take effect .I know that
> gtk_main() raise a message loop and do-while is another loop . How can I
> make them work together? MultiThread program maybe a way to go and I
> tried but failed when i put some gtk-about code in DoSomething(). How
> should I do then? 
> 
> Help me ,thanks! 
> ¥




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