Page MenuHomePhabricator

Client Server Programming
Updated 2,413 Days AgoPublic

This document was moved from /w/examples/ecore_con_server_client/.

PURPOSE
UI Client applications need to talk to other processes or serve requests from other apps.
Ecore Con Client and Server functions let your application implement client and server functions without getting down and dirty with sockets.
It handles the socket layer abstraction for you, while you can focus on what your app needs to do.
Let us see how it is done.

The Server

#include <Ecore.h>
#include <Ecore_Con.h>
#include <Elementary.h>

Eina_Bool client_add(void *data, int type, Ecore_Con_Event_Client_Add *ev)
{
    //server logic
    return ECORE_CALLBACK_RENEW;
}
Eina_Bool client_del(void *data, int type, Ecore_Con_Event_Client_Del *ev)
{
    //server logic
    return ECORE_CALLBACK_RENEW;
}
Eina_Bool client_data(void *data, int type, Ecore_Con_Event_Client_Data *ev)
{
    //server logic
    return ECORE_CALLBACK_RENEW;
}
int main(int argc, char *argv[])
{
    Ecore_Con_Server *srv;
    const char *address = "127.0.0.1";
    int port = 8080;
    elm_init(argc, argv);
    if ((svr = ecore_con_server_add(ECORE_CON_REMOTE_TCP, address, port, NULL)))
    {
        ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD,client_add, NULL);
        ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, client_del, NULL);
        ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, client_data, NULL);
    }
    elm_run();
    elm_shutdown();
}

The Client

#include <Ecore.h>
#include <Ecore_Con.h>
#include <Elementary.h>

Eina_Bool connected_to_server(void *data, int type, Ecore_Con_Event_Server_Add *ev)
{
   //client logic
   return ECORE_CALLBACK_RENEW;
}
Eina_Bool disconnected_from_server(void *data, int type, Ecore_Con_Event_Server_Del *ev)
{
   //client logic
   return ECORE_CALLBACK_RENEW;
}
Eina_Bool data_from_server(void *data, int type, Ecore_Con_Event_Server_Data *ev)
{
   //client logic
   return ECORE_CALLBACK_RENEW;
}
int main(int argc, const char *argv[])
{
    Ecore_Con_Server *svr;
    const char *address = "127.0.0.1";
    int port = 8080;
    elm_init(argc, argv);
    if ((svr = ecore_con_server_connect(ECORE_CON_REMOTE_TCP, address, port, NULL)))
    {
        ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, connected_to_server, NULL);
        ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, disconnected_from_server, NULL);
        ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, data_from_server, NULL);
    }
    elm_run();
    elm_shutdown();
}

For the more perfect and curious
Client Code
Server Code

Last Author
sanjeev
Last Edited
Feb 12 2014, 5:39 PM
Projects
None
Subscribers
seoz