\hypertarget{ecore_con_server_simple_example_8c-example}{}\doxysection{ecore\+\_\+con\+\_\+server\+\_\+simple\+\_\+example.\+c}
Shows how to setup a simple server that accepts client connections and sends a \char`\"{}hello\char`\"{} string to them. See the complete example description at \mbox{\hyperlink{ecore_con_server_simple_example_c}{Ecore\+\_\+\+Con -\/ Creating a server}}


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile with:}}
\DoxyCodeLine{\textcolor{comment}{// gcc -\/o ecore\_con\_server\_simple\_example ecore\_con\_server\_simple\_example.c `pkg-\/config -\/-\/libs -\/-\/cflags ecore ecore-\/con eina`}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <stdio.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <Ecore.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <Ecore\_Con.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{struct }\_Client}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keywordtype}{int} sdata;}
\DoxyCodeLine{\};}
\DoxyCodeLine{}
\DoxyCodeLine{\mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_add(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{int} type \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \mbox{\hyperlink{struct__Ecore__Con__Event__Client__Add}{Ecore\_Con\_Event\_Client\_Add}} *ev)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keywordtype}{char} welcome[] = \textcolor{stringliteral}{"{}hello! -\/ sent from the server"{}};}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga80f90f9716013d6104624c2e606f8915}{Ecore\_Con\_Server}} *srv;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Client__Group_gae9afe250f5420f4731d1a94050275756}{Ecore\_Con\_Client}} *cl;}
\DoxyCodeLine{   \textcolor{keyword}{const} \mbox{\hyperlink{struct__Eina__List}{Eina\_List}} *clients, *l;}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keyword}{struct }\_Client *client = malloc(\textcolor{keyword}{sizeof}(*client));}
\DoxyCodeLine{   client-\/>sdata = 0;}
\DoxyCodeLine{}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}Client with ip \%s, port \%d, connected = \%d!\(\backslash\)n"{}},}
\DoxyCodeLine{          \mbox{\hyperlink{group__Ecore__Con__Client__Group_ga4ad07ad82fe87998baaf8779fe8fe306}{ecore\_con\_client\_ip\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Add_a9877727e79213077e8592dfca5895cbe}{client}}),}
\DoxyCodeLine{          \mbox{\hyperlink{group__Ecore__Con__Client__Group_gaba3cd4f92dab4d4bc810bc34c7cce845}{ecore\_con\_client\_port\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Add_a9877727e79213077e8592dfca5895cbe}{client}}),}
\DoxyCodeLine{          \mbox{\hyperlink{group__Ecore__Con__Client__Group_gadd393b1a3b1407af2e0e778a3a0bfb7d}{ecore\_con\_client\_connected\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Add_a9877727e79213077e8592dfca5895cbe}{client}}));}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Client__Group_ga50369a811bc465c1816375b51610fbb5}{ecore\_con\_client\_send}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Add_a9877727e79213077e8592dfca5895cbe}{client}}, welcome, \textcolor{keyword}{sizeof}(welcome));}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Client__Group_ga9a117cad0d888cf2f55dc0ff4d268b7d}{ecore\_con\_client\_flush}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Add_a9877727e79213077e8592dfca5895cbe}{client}});}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Client__Group_gae7a9b17f228933fdadbfc7423683ae68}{ecore\_con\_client\_timeout\_set}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Add_a9877727e79213077e8592dfca5895cbe}{client}}, 6);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Client__Group_ga06559d231bd1f75ec6236398a0605d3d}{ecore\_con\_client\_data\_set}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Add_a9877727e79213077e8592dfca5895cbe}{client}}, client);}
\DoxyCodeLine{}
\DoxyCodeLine{   srv = \mbox{\hyperlink{group__Ecore__Con__Client__Group_ga443b991fa68473b8bca43221ac196e26}{ecore\_con\_client\_server\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Add_a9877727e79213077e8592dfca5895cbe}{client}});}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}Clients connected to this server:\(\backslash\)n"{}});}
\DoxyCodeLine{   clients = \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga717c40d71e873dd34d9d9c62fbb2d454}{ecore\_con\_server\_clients\_get}}(srv);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__List__Group_gac6efafc19f526d916cdb9757240a8773}{EINA\_LIST\_FOREACH}}(clients, l, cl)}
\DoxyCodeLine{     printf(\textcolor{stringliteral}{"{}\%s\(\backslash\)n"{}}, \mbox{\hyperlink{group__Ecore__Con__Client__Group_ga4ad07ad82fe87998baaf8779fe8fe306}{ecore\_con\_client\_ip\_get}}(cl));}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_del(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{int} type \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \mbox{\hyperlink{struct__Ecore__Con__Event__Client__Del}{Ecore\_Con\_Event\_Client\_Del}} *ev)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keyword}{struct }\_Client *client;}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Del_a47278613bc4acaf1d9f3e8c217fd2035}{client}})}
\DoxyCodeLine{     \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};}
\DoxyCodeLine{}
\DoxyCodeLine{   client = \mbox{\hyperlink{group__Ecore__Con__Client__Group_ga608a3e4b05e73bdfe6da9fb499db91ad}{ecore\_con\_client\_data\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Del_a47278613bc4acaf1d9f3e8c217fd2035}{client}});}
\DoxyCodeLine{}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}Lost client with ip \%s!\(\backslash\)n"{}}, \mbox{\hyperlink{group__Ecore__Con__Client__Group_ga4ad07ad82fe87998baaf8779fe8fe306}{ecore\_con\_client\_ip\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Del_a47278613bc4acaf1d9f3e8c217fd2035}{client}}));}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (client)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        printf(\textcolor{stringliteral}{"{}Total data received from this client: \%d\(\backslash\)n"{}}, client-\/>sdata);}
\DoxyCodeLine{        free(client);}
\DoxyCodeLine{     \}}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}Client was connected for \%0.3f seconds.\(\backslash\)n"{}},}
\DoxyCodeLine{          \mbox{\hyperlink{group__Ecore__Con__Client__Group_gaa2e41cada91ff44847e3d8d45c9a1edf}{ecore\_con\_client\_uptime\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Del_a47278613bc4acaf1d9f3e8c217fd2035}{client}}));}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Client__Group_gafbd8685a4405541b93f350308826fd44}{ecore\_con\_client\_del}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Del_a47278613bc4acaf1d9f3e8c217fd2035}{client}});}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_data(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{int} type \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \mbox{\hyperlink{struct__Ecore__Con__Event__Client__Data}{Ecore\_Con\_Event\_Client\_Data}} *ev)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keywordtype}{char} fmt[128];}
\DoxyCodeLine{   \textcolor{keyword}{struct }\_Client *client = \mbox{\hyperlink{group__Ecore__Con__Client__Group_ga608a3e4b05e73bdfe6da9fb499db91ad}{ecore\_con\_client\_data\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Data_a2c3e5b340b67fde235d2da9814f3d413}{client}});}
\DoxyCodeLine{}
\DoxyCodeLine{   snprintf(fmt, \textcolor{keyword}{sizeof}(fmt),}
\DoxyCodeLine{            \textcolor{stringliteral}{"{}Received \%i bytes from client \%s port \%d:\(\backslash\)n"{}}}
\DoxyCodeLine{            \textcolor{stringliteral}{"{}>>>>>\(\backslash\)n"{}}}
\DoxyCodeLine{            \textcolor{stringliteral}{"{}\%\%.\%is\(\backslash\)n"{}}}
\DoxyCodeLine{            \textcolor{stringliteral}{"{}>>>>>\(\backslash\)n"{}},}
\DoxyCodeLine{            ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Data_a6e87f88d094ec774fb22133a0632d8b3}{size}}, \mbox{\hyperlink{group__Ecore__Con__Client__Group_ga4ad07ad82fe87998baaf8779fe8fe306}{ecore\_con\_client\_ip\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Data_a2c3e5b340b67fde235d2da9814f3d413}{client}}),}
\DoxyCodeLine{            \mbox{\hyperlink{group__Ecore__Con__Client__Group_gaba3cd4f92dab4d4bc810bc34c7cce845}{ecore\_con\_client\_port\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Data_a2c3e5b340b67fde235d2da9814f3d413}{client}}), ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Data_a6e87f88d094ec774fb22133a0632d8b3}{size}});}
\DoxyCodeLine{}
\DoxyCodeLine{   printf(fmt, ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Data_a1e2cdb017a18b0515d2102edc016b4c5}{data}});}
\DoxyCodeLine{}
\DoxyCodeLine{   client-\/>sdata += ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Client__Data_a6e87f88d094ec774fb22133a0632d8b3}{size}};}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}}
\DoxyCodeLine{main(\textcolor{keywordtype}{void})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga80f90f9716013d6104624c2e606f8915}{Ecore\_Con\_Server}} *svr;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Client__Group_gae9afe250f5420f4731d1a94050275756}{Ecore\_Con\_Client}} *cl;}
\DoxyCodeLine{   \textcolor{keyword}{const} \mbox{\hyperlink{struct__Eina__List}{Eina\_List}} *clients, *l;}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Main__Group_gafee4bfc0e509b6ffed6598edf6f4b3de}{eina\_init}}();}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Init__Group_ga77757609684a2c922dc5ec398274751b}{ecore\_init}}();}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Lib__Group_gacf5ecf42c516bb9c8b6759721e9559bd}{ecore\_con\_init}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!(svr = \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga80bb3260bf5589f31a480b5ead27a2be}{ecore\_con\_server\_add}}(ECORE\_CON\_REMOTE\_TCP, \textcolor{stringliteral}{"{}127.0.0.1"{}}, 8080, NULL)))}
\DoxyCodeLine{     exit(1);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Event__Group_gae75b0b1b2c50e73b8e42afc628b00a62}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Con__Events__Group_ga2ccb9d84c4e5480a787e4672af3e353f}{ECORE\_CON\_EVENT\_CLIENT\_ADD}}, (\mbox{\hyperlink{group__Ecore__Event__Group_ga64b4df04cbafda481593d0bc29617c6d}{Ecore\_Event\_Handler\_Cb}})\_add, NULL);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Event__Group_gae75b0b1b2c50e73b8e42afc628b00a62}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Con__Events__Group_ga0daddd73ab2ab92cbfd91f50ea344e12}{ECORE\_CON\_EVENT\_CLIENT\_DEL}}, (\mbox{\hyperlink{group__Ecore__Event__Group_ga64b4df04cbafda481593d0bc29617c6d}{Ecore\_Event\_Handler\_Cb}})\_del, NULL);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Event__Group_gae75b0b1b2c50e73b8e42afc628b00a62}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Con__Events__Group_gafb9ce301001338915a45969e4d11d016}{ECORE\_CON\_EVENT\_CLIENT\_DATA}}, (\mbox{\hyperlink{group__Ecore__Event__Group_ga64b4df04cbafda481593d0bc29617c6d}{Ecore\_Event\_Handler\_Cb}})\_data, NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Server__Group_gabcfc2fa5861fa9831bcd99ffdc27e88c}{ecore\_con\_server\_timeout\_set}}(svr, 10);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga1d0299636c42e05621bb51c93e727291}{ecore\_con\_server\_client\_limit\_set}}(svr, 3, 0);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   clients = \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga717c40d71e873dd34d9d9c62fbb2d454}{ecore\_con\_server\_clients\_get}}(svr);}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}Clients connected to this server when exiting: \%d\(\backslash\)n"{}},}
\DoxyCodeLine{          \mbox{\hyperlink{group__Eina__List__Group_ga301729054a498a2df09a5f1dd760697e}{eina\_list\_count}}(clients));}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__List__Group_gac6efafc19f526d916cdb9757240a8773}{EINA\_LIST\_FOREACH}}(clients, l, cl)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        printf(\textcolor{stringliteral}{"{}\%s\(\backslash\)n"{}}, \mbox{\hyperlink{group__Ecore__Con__Client__Group_ga4ad07ad82fe87998baaf8779fe8fe306}{ecore\_con\_client\_ip\_get}}(cl));}
\DoxyCodeLine{        free(\mbox{\hyperlink{group__Ecore__Con__Client__Group_ga608a3e4b05e73bdfe6da9fb499db91ad}{ecore\_con\_client\_data\_get}}(cl));}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}Server was up for \%0.3f seconds\(\backslash\)n"{}},}
\DoxyCodeLine{          \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga8fa2343385b497c3deff5fab7670637a}{ecore\_con\_server\_uptime\_get}}(svr));}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Lib__Group_gaccfd8dd2a1187b71339b5cc39dc83938}{ecore\_con\_shutdown}}();}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}}();}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Main__Group_ga2c8b4020427108a30c44707af22c99d3}{eina\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}

\end{DoxyCodeInclude}
 