\hypertarget{ecore_con_client_simple_example_8c-example}{}\doxysection{ecore\+\_\+con\+\_\+client\+\_\+simple\+\_\+example.\+c}
Shows how to setup a simple client that connects to a server and sends a \char`\"{}hello\char`\"{} string to it.

Shows how to setup a simple client that connects to a server and sends a \char`\"{}hello\char`\"{} string to it. See the complete example description at \mbox{\hyperlink{ecore_con_client_simple_example_c}{Ecore\+\_\+\+Con -\/ Creating a client}}


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile\ with:}}
\DoxyCodeLine{\textcolor{comment}{//\ gcc\ -\/o\ ecore\_con\_client\_simple\_example\ ecore\_con\_client\_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\ }\_Server}
\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__Server__Add}{Ecore\_Con\_Event\_Server\_Add}}\ *ev)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{char}\ welcome[]\ =\ \textcolor{stringliteral}{"{}hello!\ -\/\ sent\ from\ the\ client"{}};}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{struct\ }\_Server\ *server\ =\ malloc(\textcolor{keyword}{sizeof}(*server));}
\DoxyCodeLine{\ \ \ server-\/>sdata\ =\ 0;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga272d6a2100f55d7c9adf44edfa493453}{ecore\_con\_server\_data\_set}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Add_a382a9545ed7fb941a30dc4d598dc7e4d}{server}},\ server);}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}Server\ with\ ip\ \%s,\ name\ \%s,\ port\ \%d,\ connected\ =\ \%d!\(\backslash\)n"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga69fe8d9a0423028446b7e2fd873092de}{ecore\_con\_server\_ip\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Add_a382a9545ed7fb941a30dc4d598dc7e4d}{server}}),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga8794c4cebaa94f553ed7fd067edad090}{ecore\_con\_server\_name\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Add_a382a9545ed7fb941a30dc4d598dc7e4d}{server}}),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga2594c94da97401d08463fba7b9c1b0a2}{ecore\_con\_server\_port\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Add_a382a9545ed7fb941a30dc4d598dc7e4d}{server}}),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Con__Server__Group_gab0c376cb6b6b8f3e8e96b4f4cbe86a3d}{ecore\_con\_server\_connected\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Add_a382a9545ed7fb941a30dc4d598dc7e4d}{server}}));}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Con__Server__Group_gad01efce916804c31f6b2adcc6f607c6b}{ecore\_con\_server\_send}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Add_a382a9545ed7fb941a30dc4d598dc7e4d}{server}},\ welcome,\ \textcolor{keyword}{sizeof}(welcome));}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Con__Server__Group_gac1768fae815fb830a2df13ef08a2e5ae}{ecore\_con\_server\_flush}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Add_a382a9545ed7fb941a30dc4d598dc7e4d}{server}});}
\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__Server__Del}{Ecore\_Con\_Event\_Server\_Del}}\ *ev)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Del_a116963b404600e7154c61f94ebf52a2e}{server}})}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}Failed\ to\ establish\ connection\ to\ the\ server.\(\backslash\)nExiting.\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}}();}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{struct\ }\_Server\ *server\ =\ \mbox{\hyperlink{group__Ecore__Con__Server__Group_gaa2d84f142e670a7db42070b48bad9c0a}{ecore\_con\_server\_data\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Del_a116963b404600e7154c61f94ebf52a2e}{server}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ printf(\textcolor{stringliteral}{"{}Lost\ server\ with\ ip\ \%s!\(\backslash\)n"{}},\ \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga69fe8d9a0423028446b7e2fd873092de}{ecore\_con\_server\_ip\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Del_a116963b404600e7154c61f94ebf52a2e}{server}}));}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (server)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}Total\ data\ received\ from\ this\ server:\ \%d\(\backslash\)n"{}},\ server-\/>sdata);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ free(server);}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga2c73087dc4a05e80446a64e7420f87a3}{ecore\_con\_server\_del}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Del_a116963b404600e7154c61f94ebf52a2e}{server}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}}();}
\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__Server__Data}{Ecore\_Con\_Event\_Server\_Data}}\ *ev)}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{char}\ fmt[128];}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{struct\ }\_Server\ *server\ =\ \mbox{\hyperlink{group__Ecore__Con__Server__Group_gaa2d84f142e670a7db42070b48bad9c0a}{ecore\_con\_server\_data\_get}}(ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Data_a632e6c0033302088e26479c4fa17e0c0}{server}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ snprintf(fmt,\ \textcolor{keyword}{sizeof}(fmt),}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}Received\ \%i\ bytes\ from\ server:\(\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__Server__Data_a41877d1f1cb9792508b9b1d89d53bec2}{size}},\ ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Data_a41877d1f1cb9792508b9b1d89d53bec2}{size}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ printf(fmt,\ ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Data_a8d45b6d75c55b26771d241211a0d7e7e}{data}});}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ server-\/>sdata\ +=\ ev-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Data_a41877d1f1cb9792508b9b1d89d53bec2}{size}};}
\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}{int}\ argc,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *argv[])}
\DoxyCodeLine{\{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga80f90f9716013d6104624c2e606f8915}{Ecore\_Con\_Server}}\ *svr;}
\DoxyCodeLine{\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *address;}
\DoxyCodeLine{\ \ \ \textcolor{keywordtype}{int}\ port\ =\ 8080;}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (argc\ <\ 2)}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}wrong\ usage.\ Command\ syntax\ is:\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}\(\backslash\)tecore\_con\_client\_simple\_example\ <address>\ [port]\(\backslash\)n"{}});}
\DoxyCodeLine{\ \ \ \ \ \ \ \ exit(1);}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ address\ =\ argv[1];}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (argc\ >\ 2)}
\DoxyCodeLine{\ \ \ \ \ port\ =\ atoi(argv[2]);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Main__Group_ga81b8137665b8a4d2cb38ca50017d4c74}{eina\_init}}();}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Init__Group_ga77757609684a2c922dc5ec398274751b}{ecore\_init}}();}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Con__Lib__Group_ga8a20f47372627a03e86a8705a6f8a82d}{ecore\_con\_init}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{if}\ (!(svr\ =\ \mbox{\hyperlink{group__Ecore__Con__Server__Group_gab1bc5a7692c3c36af00e1ac1db257e98}{ecore\_con\_server\_connect}}(ECORE\_CON\_REMOTE\_TCP,\ address,\ port,\ NULL)))}
\DoxyCodeLine{\ \ \ \ \ \{}
\DoxyCodeLine{\ \ \ \ \ \ \ \ printf(\textcolor{stringliteral}{"{}could\ not\ connect\ to\ the\ server:\ \%s,\ port\ \%d.\(\backslash\)n"{}},}
\DoxyCodeLine{\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ address,\ port);}
\DoxyCodeLine{\ \ \ \ \ \ \ \ exit(2);}
\DoxyCodeLine{\ \ \ \ \ \}}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ set\ event\ handler\ for\ server\ connect\ */}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Event__Group_ga886c90c3f917f87b3b4c931adcbc41c5}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Con__Events__Group_ga333583a2fbee7c0e3e7fda4a829340be}{ECORE\_CON\_EVENT\_SERVER\_ADD}},\ (\mbox{\hyperlink{group__Ecore__Event__Group_ga64b4df04cbafda481593d0bc29617c6d}{Ecore\_Event\_Handler\_Cb}})\_add,\ NULL);}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ set\ event\ handler\ for\ server\ disconnect\ */}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Event__Group_ga886c90c3f917f87b3b4c931adcbc41c5}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Con__Events__Group_ga8577770d5208d3f03d6fbfd1880334ea}{ECORE\_CON\_EVENT\_SERVER\_DEL}},\ (\mbox{\hyperlink{group__Ecore__Event__Group_ga64b4df04cbafda481593d0bc29617c6d}{Ecore\_Event\_Handler\_Cb}})\_del,\ NULL);}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ set\ event\ handler\ for\ receiving\ server\ data\ */}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Event__Group_ga886c90c3f917f87b3b4c931adcbc41c5}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Con__Events__Group_gac42c3834093f29434298daedd421b2ed}{ECORE\_CON\_EVENT\_SERVER\_DATA}},\ (\mbox{\hyperlink{group__Ecore__Event__Group_ga64b4df04cbafda481593d0bc29617c6d}{Ecore\_Event\_Handler\_Cb}})\_data,\ NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{comment}{/*\ start\ client\ */}}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Con__Lib__Group_ga0e5e01c67f7135e16db0e8f17d087d99}{ecore\_con\_shutdown}}();}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}}();}
\DoxyCodeLine{\ \ \ \mbox{\hyperlink{group__Eina__Main__Group_ga5bf35513199d5220341437c05696285d}{eina\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}

\end{DoxyCodeInclude}
 