8 accept_callback (GSocket *socket, GAsyncResult *result, gpointer data)
12 if (!g_socket_connect_finish (socket, result, &error)) {
13 g_warning (error->message);
17 g_print ("successfully connected\n");
21 int main (int argc, char *argv[])
25 GOutputStream *output;
27 gchar buffer[512] = {0};
34 loop = g_main_loop_new (NULL, FALSE);
36 client = g_tcp_client_new ("www.google.com", 80);
38 g_print ("connecting to www.google.com:80\n");
40 if (!g_tcp_client_connect (client, NULL, &error)) {
41 g_warning (error->message);
45 g_print ("connected!\n");
47 output = G_OUTPUT_STREAM (g_tcp_client_get_output_stream (client));
49 input = G_INPUT_STREAM (g_tcp_client_get_input_stream (client));
51 g_print ("writing...\n");
53 if ((count = g_output_stream_write (output, "GET / HTTP/1.0\r\n\r\n", 19, NULL, &error)) < 0) {
54 g_warning (error->message);
58 g_print ("wrote %d bytes\n", count);
60 if ((count = g_input_stream_read (input, buffer, 512, NULL, &error)) < 0) {
61 g_warning (error->message);
65 g_print ("read %d bytes: %s\n", count, buffer);
67 g_object_unref (G_OBJECT (client));
69 // g_main_loop_run (loop);