\hypertarget{ecore_con_client_example_8c-example}{\section{ecore\+\_\+con\+\_\+client\+\_\+example.\+c}
}
Shows how to write a simple client that connects to the example server.


\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{// gcc -o ecore\_con\_client\_example ecore\_con\_client\_example.c `pkg-config --libs --cflags ecore ecore-con
       eina`}

\textcolor{preprocessor}{#ifdef HAVE\_CONFIG\_H}
\textcolor{preprocessor}{#include "config.h"}
\textcolor{preprocessor}{#endif}

\textcolor{preprocessor}{#include <stdio.h>}
\textcolor{preprocessor}{#include <Ecore.h>}
\textcolor{preprocessor}{#include <Ecore\_Con.h>}

\textcolor{comment}{/* Ecore\_Con client example}
\textcolor{comment}{ * 2010 Mike Blumenkrantz}
\textcolor{comment}{ */}

\textcolor{preprocessor}{#ifdef HAVE\_GNUTLS}
\textcolor{preprocessor}{#include <gnutls/gnutls.h>}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
tls\_log\_func(\textcolor{keywordtype}{int} level, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *str)
\{
   fprintf(stderr, \textcolor{stringliteral}{"|<%d>| %s"}, level, str);
\}
\textcolor{preprocessor}{#endif}

\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_add(\textcolor{keywordtype}{void} *data EINA\_UNUSED, \textcolor{keywordtype}{int} type EINA\_UNUSED, \hyperlink{struct__Ecore__Con__Event__Server__Add}{Ecore\_Con\_Event\_Server\_Add} *ev
      )
\{
   printf(\textcolor{stringliteral}{"Server with ip %s connected!\(\backslash\)n"}, \hyperlink{group__Ecore__Con__Server__Group_gaea2a907ae4ca478a360928fd16654d45}{ecore\_con\_server\_ip\_get}(ev->
      \hyperlink{struct__Ecore__Con__Event__Server__Add_a382a9545ed7fb941a30dc4d598dc7e4d}{server}));
   \hyperlink{group__Ecore__Con__Server__Group_gadf16abc2d4fc16a8b65709eab2cd8337}{ecore\_con\_server\_send}(ev->\hyperlink{struct__Ecore__Con__Event__Server__Add_a382a9545ed7fb941a30dc4d598dc7e4d}{server}, \textcolor{stringliteral}{"hello!"}, 6);
   \hyperlink{group__Ecore__Con__Server__Group_ga3ddb6c88484b59a1f5a5bacb8b6e60fe}{ecore\_con\_server\_flush}(ev->\hyperlink{struct__Ecore__Con__Event__Server__Add_a382a9545ed7fb941a30dc4d598dc7e4d}{server});

   \textcolor{keywordflow}{return} \hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW};
\}

\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_del(\textcolor{keywordtype}{void} *data EINA\_UNUSED, \textcolor{keywordtype}{int} type EINA\_UNUSED, \hyperlink{struct__Ecore__Con__Event__Server__Del}{Ecore\_Con\_Event\_Server\_Del} *ev
      )
\{
   printf(\textcolor{stringliteral}{"Lost server with ip %s!\(\backslash\)n"}, \hyperlink{group__Ecore__Con__Server__Group_gaea2a907ae4ca478a360928fd16654d45}{ecore\_con\_server\_ip\_get}(ev->
      \hyperlink{struct__Ecore__Con__Event__Server__Del_a116963b404600e7154c61f94ebf52a2e}{server}));
   \hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}();
   \textcolor{keywordflow}{return} \hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW};
\}

\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_data(\textcolor{keywordtype}{void} *data EINA\_UNUSED, \textcolor{keywordtype}{int} type EINA\_UNUSED, \hyperlink{struct__Ecore__Con__Event__Server__Data}{Ecore\_Con\_Event\_Server\_Data} 
      *ev)
\{
   \textcolor{keywordtype}{char} fmt[128];

   snprintf(fmt, \textcolor{keyword}{sizeof}(fmt),
            \textcolor{stringliteral}{"Received %i bytes from server:\(\backslash\)n"}
            \textcolor{stringliteral}{">>>>>\(\backslash\)n"}
            \textcolor{stringliteral}{"%%.%is\(\backslash\)n"}
            \textcolor{stringliteral}{">>>>>\(\backslash\)n"},
            ev->\hyperlink{struct__Ecore__Con__Event__Server__Data_a41877d1f1cb9792508b9b1d89d53bec2}{size}, ev->\hyperlink{struct__Ecore__Con__Event__Server__Data_a41877d1f1cb9792508b9b1d89d53bec2}{size});

   printf(fmt, ev->\hyperlink{struct__Ecore__Con__Event__Server__Data_a8d45b6d75c55b26771d241211a0d7e7e}{data});
   \textcolor{keywordflow}{return} \hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW};
\}

\textcolor{keywordtype}{int}
main()
\{
   Ecore\_Con\_Server *svr;
   \hyperlink{struct__Eina__Iterator}{Eina\_Iterator} *it;
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *ca;

   \hyperlink{group__Eina__Main__Group_gabf448ada5bc81a07342b66c6f818ee5e}{eina\_init}();
   \hyperlink{group__Ecore__Init__Group_ga77757609684a2c922dc5ec398274751b}{ecore\_init}();
   \hyperlink{group__Ecore__Con__Events__Group_gacf5ecf42c516bb9c8b6759721e9559bd}{ecore\_con\_init}();

\textcolor{preprocessor}{#ifdef HAVE\_GNUTLS}
   gnutls\_global\_set\_log\_level(9);
   gnutls\_global\_set\_log\_function(tls\_log\_func);
\textcolor{preprocessor}{#endif}

   \textcolor{keywordflow}{if} (!(it = \hyperlink{group__Eina__File__Group_ga8c4fabb379b865a4ec134a5c4436be2a}{eina\_file\_ls}(\textcolor{stringliteral}{"/etc/ssl/certs"})))
     exit(1);

   \textcolor{keywordflow}{if} (!(svr = \hyperlink{group__Ecore__Con__Server__Group_gae3d7391f7da5e0f748d7b6804d010b2f}{ecore\_con\_server\_connect}(
      \hyperlink{group__Ecore__Con__Lib__Group_gga4862bfa05383e6e16a1dfc6eafc90564ab02a4b8522d1ed409cfb24131b24c4ed}{ECORE\_CON\_REMOTE\_TCP} | \hyperlink{group__Ecore__Con__Lib__Group_gga4862bfa05383e6e16a1dfc6eafc90564affce37f8fe14079678f0cef5030bc599}{ECORE\_CON\_USE\_MIXED}, \textcolor{stringliteral}{"www.verisign.com"}, 443,
       NULL)))
     exit(1);

   \textcolor{comment}{/* add all the CAs */}
   \hyperlink{group__Eina__Iterator__Group_gad2f796ac4df0e500d25235c29821faa3}{EINA\_ITERATOR\_FOREACH}(it, ca)
     \{
        \textcolor{keywordflow}{if} (!\hyperlink{group__Ecore__Con__SSL__Group_gada17e3b9022fc710a4d235f3c45b1dfa}{ecore\_con\_ssl\_server\_cafile\_add}(svr, ca))
          printf(\textcolor{stringliteral}{"Could not load CA: %s!\(\backslash\)n"}, ca);
        \hyperlink{group__Eina__Stringshare__Group_ga4453d2aff2b325c7b45048f30df9b1f5}{eina\_stringshare\_del}(ca);
     \}

   \hyperlink{group__Eina__Iterator__Group_gaf9261991a4b05dc63e3401278a3281f8}{eina\_iterator\_free}(it);
   \hyperlink{group__Ecore__Con__SSL__Group_ga2fbf3430cf98dfdd2a7d5e384edf56c4}{ecore\_con\_ssl\_server\_verify}(svr);

\textcolor{comment}{/* set event handler for server connect */}
   \hyperlink{group__Ecore__Event__Group_gae75b0b1b2c50e73b8e42afc628b00a62}{ecore\_event\_handler\_add}(\hyperlink{group__Ecore__Con__Events__Group_ga4eed60012259c24f9ac75852c5ec1950}{ECORE\_CON\_EVENT\_SERVER\_ADD}, (
      \hyperlink{group__Ecore__Event__Group_ga64b4df04cbafda481593d0bc29617c6d}{Ecore\_Event\_Handler\_Cb})\_add, NULL);
\textcolor{comment}{/* set event handler for server disconnect */}
   \hyperlink{group__Ecore__Event__Group_gae75b0b1b2c50e73b8e42afc628b00a62}{ecore\_event\_handler\_add}(\hyperlink{group__Ecore__Con__Events__Group_gabf1abac1d209506c2813837e36dfe37b}{ECORE\_CON\_EVENT\_SERVER\_DEL}, (
      \hyperlink{group__Ecore__Event__Group_ga64b4df04cbafda481593d0bc29617c6d}{Ecore\_Event\_Handler\_Cb})\_del, NULL);
\textcolor{comment}{/* set event handler for receiving server data */}
   \hyperlink{group__Ecore__Event__Group_gae75b0b1b2c50e73b8e42afc628b00a62}{ecore\_event\_handler\_add}(\hyperlink{group__Ecore__Con__Events__Group_ga4bd54e9f3c04f7d601bd15b2e109f050}{ECORE\_CON\_EVENT\_SERVER\_DATA}, (
      \hyperlink{group__Ecore__Event__Group_ga64b4df04cbafda481593d0bc29617c6d}{Ecore\_Event\_Handler\_Cb})\_data, NULL);

\textcolor{comment}{/* start client */}
   \hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}();
\}

\end{DoxyCodeInclude}
 