summaryrefslogtreecommitdiff
path: root/legacy/ecore
diff options
context:
space:
mode:
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>2010-09-20 21:16:51 +0000
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>2010-09-20 21:16:51 +0000
commit101089c62e09de2654410e13f5f8ecaa7eead663 (patch)
tree02136461ee90152c869248d16c7e22ab10d29e93 /legacy/ecore
parent45e75f937e72116848f64226adc99d8a38a98fe3 (diff)
ecore_con client example
SVN revision: 52517
Diffstat (limited to '')
-rw-r--r--legacy/ecore/examples/ecore_con_client_example.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/legacy/ecore/examples/ecore_con_client_example.c b/legacy/ecore/examples/ecore_con_client_example.c
new file mode 100644
index 0000000000..9c4afc8f97
--- /dev/null
+++ b/legacy/ecore/examples/ecore_con_client_example.c
@@ -0,0 +1,83 @@
1#include <stdio.h>
2#include <Ecore.h>
3#include <Ecore_Con.h>
4
5/* Ecore_Con client example
6 * 2010 Mike Blumenkrantz
7 */
8
9/* uncomment if using gnutls
10static void
11tls_log_func(int level, const char *str)
12{
13 fprintf(stderr, "|<%d>| %s", level, str);
14}
15*/
16
17Eina_Bool
18_add(void *data, int type, Ecore_Con_Event_Server_Add *ev)
19{
20 printf("Server with ip %s connected!\n", ecore_con_server_ip_get(ev->server));
21 ecore_con_server_send(ev->server, "hello!", 6);
22 ecore_con_server_flush(ev->server);
23 ecore_con_server_del(ev->server);
24
25 return ECORE_CALLBACK_RENEW;
26}
27
28
29Eina_Bool
30_del(void *data, int type, Ecore_Con_Event_Server_Del *ev)
31{
32 printf("Lost server with ip %s!\n", ecore_con_server_ip_get(ev->server));
33 return ECORE_CALLBACK_RENEW;
34}
35
36Eina_Bool
37_data(void *data, int type, Ecore_Con_Event_Server_Data *ev)
38{
39 char fmt[128];
40
41 snprintf(fmt, sizeof(fmt),
42 "Received %i bytes from server:\n"
43 ">>>>>\n"
44 "%%.%is\n"
45 ">>>>>\n",
46 ev->size, ev->size);
47
48 printf(fmt, ev->data);
49 return ECORE_CALLBACK_RENEW;
50}
51int main()
52{
53 eina_init();
54 ecore_init();
55 ecore_con_init();
56
57/* uncomment if using gnutls
58 gnutls_global_set_log_level(9);
59 gnutls_global_set_log_function(tls_log_func);
60*/
61
62
63/* to use a PEM certificate with TLS and SSL3, uncomment the lines below */
64/*
65 if ((!ecore_con_server_ssl_cert_add("server.pem")))
66 printf("Error loading certificate!\n");
67
68 ecore_con_server_connect(ECORE_CON_REMOTE_TCP | ECORE_CON_USE_TLS | ECORE_CON_USE_SSL3 | ECORE_CON_LOAD_CERT, "127.0.0.1", 8080, NULL);
69*/
70
71/* to use simple tcp without ssl/tls, use this line */
72 ecore_con_server_connect(ECORE_CON_REMOTE_TCP, "127.0.0.1", 8080, NULL);
73
74/* set event handler for server connect */
75 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_add, NULL);
76/* set event handler for server disconnect */
77 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, (Ecore_Event_Handler_Cb)_del, NULL);
78/* set event handler for receiving server data */
79 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, (Ecore_Event_Handler_Cb)_data, NULL);
80
81/* start client */
82 ecore_main_loop_begin();
83}