X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fgnio.git;a=blobdiff_plain;f=test%2Ftest-tcp-client.c;h=467d172dfaae1f84cc5aa0edef766f46c03b76b2;hp=f13aae82d258180c959ebb53866c8275fdd7f7c2;hb=08b3eba2ce5f8beafb2b8cb8fc8b08c9676adf5f;hpb=e7aa65fdc44e1989fd837b56db4af59c765f8489 diff --git a/test/test-tcp-client.c b/test/test-tcp-client.c index f13aae8..467d172 100644 --- a/test/test-tcp-client.c +++ b/test/test-tcp-client.c @@ -21,7 +21,11 @@ accept_callback (GSocket *socket, GAsyncResult *result, gpointer data) int main (int argc, char *argv[]) { GTcpClient *client; + GInputStream *input; + GOutputStream *output; GError *error = NULL; + gchar buffer[512] = {0}; + gssize count; g_thread_init (NULL); @@ -29,7 +33,7 @@ int main (int argc, char *argv[]) loop = g_main_loop_new (NULL, FALSE); - client = g_tcp_client_new ("localhost", 90); + client = g_tcp_client_new ("www.google.com", 80); g_print ("connecting to www.google.com:80\n"); @@ -40,6 +44,26 @@ int main (int argc, char *argv[]) g_print ("connected!\n"); + output = G_OUTPUT_STREAM (g_tcp_client_get_output_stream (client)); + + input = G_INPUT_STREAM (g_tcp_client_get_input_stream (client)); + + g_print ("writing...\n"); + + if ((count = g_output_stream_write (output, "GET / HTTP/1.0\r\n\r\n", 19, NULL, &error)) < 0) { + g_warning (error->message); + return 1; + } + + g_print ("wrote %d bytes\n", count); + + if ((count = g_input_stream_read (input, buffer, 512, NULL, &error)) < 0) { + g_warning (error->message); + return 1; + } + + g_print ("read %d bytes: %s\n", count, buffer); + g_object_unref (G_OBJECT (client)); // g_main_loop_run (loop);