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

Reply via email to