Re: Sockets in GTK, how to use?
Excerpts from Jacques Pelletier's message of 2011-01-31 08:16:51 +0200: } else { g_debug(%s, error-message); g_free(error); } Many thanks! This will help very much! This was pretty simple version. What I really wont to know is how to make this socket communication asynchronous. GTK docs should be more verbose... :) -- xmpp:s...@antono.info http://antono.info/ gopher://antono.info/ ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Sockets in GTK, how to use?
Excerpts from Jacques Pelletier's message of 2011-01-30 18:37:34 +0200: I'm using Gnet 2.08 in my application and I would like to convert it to GTK for its socket functions. From the docs, I was able to figure out how to open a connection, but once the connection is opened, how do we read and write to a socket? I'am begginer in this area... But something like this works for me: GSocket* socket; GSocketClient * client; GSocketConnection * connection; GSocketConnectable * addr; addr = g_network_address_new (host, port); client = g_socket_client_new (); connection = g_socket_client_connect (client, addr, NULL, error); socket = g_socket_connection_get_socket (connection); if (socket) { gchar * locator = g_strdup(data to send); g_socket_send_with_blocking(socket, locator, strlen(locator), FALSE, NULL, NULL); g_free(locator); while ( (received = g_socket_receive_with_blocking (socket, buffer, 1024, FALSE, NULL, NULL)) ) { for (buffpos = 0; buffpos received; buffpos++) { g_string_append_c(page, buffer[buffpos]); } g_debug(\n\n= Got %d/%d bytes\n\n, received, total += received); } } else { g_debug(%s, error-message); g_free(error); } PS: something as good as gnet_uri is still missing in glib/gio. I think we should move it from gnet to glib. -- xmpp:s...@antono.info http://antono.info/ gopher://antono.info/ ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Sockets in GTK, how to use?
Excerpts from Jacques Pelletier's message of 2011-01-30 18:37:34 +0200: I'm using Gnet 2.08 in my application and I would like to convert it to GTK for its socket functions. From the docs, I was able to figure out how to open a connection, but once the connection is opened, how do we read and write to a socket? I'am begginer in this area... But something like this works for me: GSocket* socket; GSocketClient * client; GSocketConnection * connection; GSocketConnectable * addr; addr = g_network_address_new (host, port); client = g_socket_client_new (); connection = g_socket_client_connect (client, addr, NULL, error); socket = g_socket_connection_get_socket (connection); if (socket) { gchar * locator = g_strdup(data to send); g_socket_send_with_blocking(socket, locator, strlen(locator), FALSE, NULL, NULL); g_free(locator); while ( (received = g_socket_receive_with_blocking (socket, buffer, 1024, FALSE, NULL, NULL)) ) { for (buffpos = 0; buffpos received; buffpos++) { g_string_append_c(page, buffer[buffpos]); } g_debug(\n\n= Got %d/%d bytes\n\n, received, total += received); } } else { g_debug(%s, error-message); g_free(error); } PS: something as good as gnet_uri is still missing in glib/gio. I think we should move it from gnet to glib. -- xmpp:s...@antono.info http://antono.info/ gopher://antono.info/ ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Sockets in GTK, how to use?
On Sunday 30 January 2011 12:03:57 Antono Vasiljev wrote: Excerpts from Jacques Pelletier's message of 2011-01-30 18:37:34 +0200: I'm using Gnet 2.08 in my application and I would like to convert it to GTK for its socket functions. From the docs, I was able to figure out how to open a connection, but once the connection is opened, how do we read and write to a socket? I'am begginer in this area... But something like this works for me: GSocket* socket; GSocketClient * client; GSocketConnection * connection; GSocketConnectable * addr; addr = g_network_address_new (host, port); client = g_socket_client_new (); connection = g_socket_client_connect (client, addr, NULL, error); socket = g_socket_connection_get_socket (connection); if (socket) { gchar * locator = g_strdup(data to send); g_socket_send_with_blocking(socket, locator, strlen(locator), FALSE, NULL, NULL); g_free(locator); while ( (received = g_socket_receive_with_blocking (socket, buffer, 1024, FALSE, NULL, NULL)) ) { for (buffpos = 0; buffpos received; buffpos++) { g_string_append_c(page, buffer[buffpos]); } g_debug(\n\n= Got %d/%d bytes\n\n, received, total += received); } } else { g_debug(%s, error-message); g_free(error); } Many thanks! This will help very much! JP PS: something as good as gnet_uri is still missing in glib/gio. I think we should move it from gnet to glib. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Sockets in GTK+?
On Mon, 2006-08-21 at 19:19 -0400, Samuel Cormier-Iijima wrote: Note that however GNet does NOT use GObject, it rolls its own object type... I kinda wanted a twisted-like framework so that I could for example subclass a GNetServer or otherwise connect signals to it to respond to network events, and GNet doesnt let you do that in the GObject way. I`m thinking I might write my own possibly... but yea other than don`t think theres been much activity on GNet for a while, the mailing lists look dead. whatever, cheers Take a look at GNetwork: http://ignore-your.tv/gnetwork/ It's GObject-based, fairly actively developed (by James Cape, a Gnome Foundation member) and in Gnome CVS (module libgnetwork). Ed On 8/21/06, Alan M. Evans [EMAIL PROTECTED] wrote: On Mon, 2006-08-21 at 06:18, Chris Sparks wrote: I went looking fo rGNet and what is odd is that it says this: It is written in C, object-oriented, and built upon GLib. C isn't object-oriented.. Object-oriented is a philosophy, not an attribute of a language. C++ supports objects within the language, C does not. But this does not mean that one cannot apply object-oriented principles when programming with C. Similarly, one could write a strictly non-object-oriented program in C++. Doing objects in C just requires some methodic discipline. Or think of it this way: All languages eventually get translated machine code. Is machine code object oriented? ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Sockets in GTK+?
On 8/20/06, n3ck [EMAIL PROTECTED] wrote: Hi every1! Im was delphi (win) coder for a while but now i use linux as OS. I really like to code so i choose GTK for build applications on linux. I have been searching for some tutorial, text or articule about how to build cliente/server apps using GTK but i could't find anything :( Somebody has some clue, url or something that helps me with this? thankz a lot. Best Regards n3ck I use the http://www.gnetlibrary.org/ library which works quite well and is well integrated into the GLib main loop. Regards, Vivien ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Sockets in GTK+?
I went looking fo rGNet and what is odd is that it says this: It is written in C, object-oriented, and built upon GLib. C isn't object-oriented.. Chris Tristan Van Berkom wrote: Luka Napotnik wrote: GTK+ is a graphical library for creating UI's. For socket programming you have to use the Unix socket API. Well that is less and less true, glib/gobject is also becomming something like an stl of choice for C programming and is widely used outside the GUI domain. You might want to look into the gnet library (google will find it), which aperently simplifies ipc programming in glib, which otherwise consists of using GIOChannel and GIOWatch sources. Cheers, -Tristan ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Sockets in GTK+?
On 8/21/06, Chris Sparks [EMAIL PROTECTED] wrote: I went looking fo rGNet and what is odd is that it says this: It is written in C, object-oriented, and built upon GLib. C isn't object-oriented.. The C language does not object, however nothing prevents you from having a Object oriented approach to programming, and the is exactly what the GLib does with the GObject object (it supports single inheritance, interfaces, properties, etc). Vivien ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Sockets in GTK+?
On Mon, 2006-08-21 at 06:18, Chris Sparks wrote: I went looking fo rGNet and what is odd is that it says this: It is written in C, object-oriented, and built upon GLib. C isn't object-oriented.. Object-oriented is a philosophy, not an attribute of a language. C++ supports objects within the language, C does not. But this does not mean that one cannot apply object-oriented principles when programming with C. Similarly, one could write a strictly non-object-oriented program in C++. Doing objects in C just requires some methodic discipline. Or think of it this way: All languages eventually get translated machine code. Is machine code object oriented? ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Sockets in GTK+?
GTK+ is a graphical library for creating UI's. For socket programming you have to use the Unix socket API. Greets, Luka On ned, 2006-08-20 at 10:18 -0500, n3ck wrote: Hi every1! Im was delphi (win) coder for a while but now i use linux as OS. I really like to code so i choose GTK for build applications on linux. I have been searching for some tutorial, text or articule about how to build cliente/server apps using GTK but i could't find anything :( Somebody has some clue, url or something that helps me with this? thankz a lot. Best Regards n3ck ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Sockets in GTK+?
Luka Napotnik wrote: GTK+ is a graphical library for creating UI's. For socket programming you have to use the Unix socket API. Well that is less and less true, glib/gobject is also becomming something like an stl of choice for C programming and is widely used outside the GUI domain. You might want to look into the gnet library (google will find it), which aperently simplifies ipc programming in glib, which otherwise consists of using GIOChannel and GIOWatch sources. Cheers, -Tristan ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Sockets with GTK 2.8.9 on WIN32
Daniel Atallah wrote: That is one of the changes that were made in Glib 2.8.x. All of the win32 GIOChannel stuff was changed such that it'll leave your sockets in non-blocking mode. See this bug report for more information: http://bugzilla.gnome.org/show_bug.cgi?id=147392 This seems very strange for me since glib 2.8 on Unix does not behave this way. How can GTK be used as a multiplatform development system if it behave in different ways for the different platform it supports? Basically, if you want your socket to be non-blocking, you have to make it so in the input function every time it is triggered. So I've to add something like this in my input function (error checking omitted): #ifdef WIN32 unsigned long par = 0; ioctlsocket(fd, FIONBIO, par); #endif This is quite ugly. I thought that I had seen this in the documentation somewhere, but apparently not. I've not found anything related to GLIB 2.6 - 2.8 differences at least at: http://www.gtk.org/api/ (incompatible differences seems related to 2.0 - 2.2 migration) Bye, Gabry ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Sockets with GTK 2.8.9 on WIN32
Gabriele Greco writes: This seems very strange for me since glib 2.8 on Unix does not behave this way. Well, Windows isn't Unix, so is it really that surprising that some things are fundamentally different? With hindsight it's easy to say that the affected APIs and abstractions in GLib should perhaps have been designed differently so that any Unix/Windows differences could have been better hidden. But, we have to make use of what we have now. Actually, I think that the original thoughts were that the affected GLib APIs (GPollFDs, GMainLoop, etc) could have been much more platform specific. Owen says in bug #120299: I don't think usage and contents of GPollFD needs to be or should be portable across Win32/Unix, though changing how it works is probably an API change on Win32. My original conception was that GMainLoop would be significantly different on different operating systems, though GPollFD * crept into more of the API (g_main_context_query()) for GTK+-2.x. That many things then turned out to be implementable on Windows without requiring ifdefs in GLib-using code was an unexpected positive surprise. Or something like that... How can GTK be used as a multiplatform development system if it behave in different ways for the different platform it supports? You just have to take those things that behave differently into account in your code. Trust me, the implementation of watched GIOChannels for sockets on Windows in GLib before 2.8 had a wholly different and more serious set of problems and Unix/Windows differences. Those caused a lot of problems when porting various GNOME platform libraries to Windows. See discussion for instance in bugs #120299 and #147392. In the old implementation there was a separate thread running per watched socket. So I've to add something like this in my input function (error checking omitted): #ifdef WIN32 unsigned long par = 0; ioctlsocket(fd, FIONBIO, par); #endif Actually I don't think that will work. As long as a socket is being watched (it has an event selection for it (WSAEventSelect()) in force) you cannot turn the non-blockingness off. Anyway, as you use GLib mainloop functionality and watched GIOchannels in the first place, isn't your intention to avoid blocking calls in your code? You perhaps want to handle reading requests from and sending replies to multiple sockets in parallel with minimum delay? Otherwise you could just use blocking recv() and send() all the time without bothering with GIOChannels and GMainLoops, couldn't you? So shouldn't you be using non-blocking mode on Unix, too, then? Aren't you otherwise just knowing your recv()/send() calls won't block (because they never do in your test environment), and when they then occasionally *do* block, perhaps indefinitely, in the end-user environment, you are in trouble? I've not found anything related to GLIB 2.6 - 2.8 differences at least at: http://www.gtk.org/api/ Yeah, the documentation needs to have a mention about it added. --tml ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Sockets with GTK 2.8.9 on WIN32
On 2/10/06, Gabriele Greco [EMAIL PROTECTED] wrote: I've a problem on an application on WIN32 with GTK 2.8.x that works flawlessly with GTK 2.6.x (always on win32) or GTK 2.8.x (on unix). It seems that with 2.8.9 (the installer version got from gimp-win home) the sockets are handled as non blocking also if you don't specify this. It's a wanted behaviour? Specifically I often receive 0 if I call recv() in my gdk_input_add( GDK_INPUT_READ ) call, this happens on GTK 2.6 and early only when the connection is closed by the remote peer. With GTK 2.8, and only on WIN32, I often receive 0 from recv and an error code of WSAEWOULDBLOCK. This is a problem since my code often rely on the fact socket calls are blocking... That is one of the changes that were made in Glib 2.8.x. All of the win32 GIOChannel stuff was changed such that it'll leave your sockets in non-blocking mode. See this bug report for more information: http://bugzilla.gnome.org/show_bug.cgi?id=147392 Basically, if you want your socket to be non-blocking, you have to make it so in the input function every time it is triggered. I thought that I had seen this in the documentation somewhere, but apparently not. -D ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Sockets
On Tue, 12 Mar 2002, Paul Davis wrote: GTK is a toolkit for creating graphical user interfaces. It has nothing to do with sockets or other IPC mechanisms, though it has some builtin support to make integrating I/O handling a little simpler. I think you need to look at another library that is focussed on this area, not GTK. He might run into problems when trying to integrate the socket IO with the gtk_main function that never returns. He needs to become familiar with monitoring the IO (14.2 in the tutorial, I think), or how to avoid using the gtk-main function. Chris ___ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list
RE: Sockets
maybe you need to use glibc library.it is more base than xlib. -Original Message- From: Chris Nystrom [mailto:[EMAIL PROTECTED]] Sent: Thursday, March 14, 2002 1:38 AM To: Paul Davis Cc: Nicolas web; [EMAIL PROTECTED] Subject: Re: Sockets On Tue, 12 Mar 2002, Paul Davis wrote: GTK is a toolkit for creating graphical user interfaces. It has nothing to do with sockets or other IPC mechanisms, though it has some builtin support to make integrating I/O handling a little simpler. I think you need to look at another library that is focussed on this area, not GTK. He might run into problems when trying to integrate the socket IO with the gtk_main function that never returns. He needs to become familiar with monitoring the IO (14.2 in the tutorial, I think), or how to avoid using the gtk-main function. Chris ___ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list ___ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list
Re: Sockets
Hi. Anyone can tell me how to make a connection IPC with GTK? I work with sockets without GTK. Exist sockets by GTK? GTK is a toolkit for creating graphical user interfaces. It has nothing to do with sockets or other IPC mechanisms, though it has some builtin support to make integrating I/O handling a little simpler. I think you need to look at another library that is focussed on this area, not GTK. --p ___ gtk-list mailing list [EMAIL PROTECTED] http://mail.gnome.org/mailman/listinfo/gtk-list