Click here to Skip to main content
15,880,427 members
Articles / Programming Languages / C

A Generic C-Language TCP Client Application

Rate me:
Please Sign up or sign in to vote.
3.67/5 (2 votes)
9 May 2010CPOL4 min read 29K   789   20  
A library for writing simple TCP client applications
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>TcpClient2: GenericClient.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
<h1>GenericClient.h</h1><a href="GenericClient_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/// @source      GenericClient.h</span>
<a name="l00002"></a>00002 <span class="comment"></span><span class="comment">/// @description Public interface for class GenericClient.</span>
<a name="l00003"></a>00003 <span class="comment"></span><span class="comment">//  See licensing information in the file README.TXT.</span>
<a name="l00004"></a>00004 
<a name="l00005"></a>00005 <span class="comment">// -----------------------------------------------------------------------------</span>
<a name="l00006"></a>00006 <span class="preprocessor">#ifndef __GENERIC_CLIENT_H__</span>
<a name="l00007"></a>00007 <span class="preprocessor"></span><span class="preprocessor">#define __GENERIC_CLIENT_H__</span>
<a name="l00008"></a>00008 <span class="preprocessor"></span><span class="comment">// -----------------------------------------------------------------------------</span>
<a name="l00009"></a>00009 
<a name="l00010"></a>00010 <span class="comment">// -----------------------------------------------------------------------------</span>
<a name="l00011"></a>00011 <span class="preprocessor">#ifdef __cplusplus</span>
<a name="l00012"></a>00012 <span class="preprocessor"></span><span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span> {
<a name="l00013"></a>00013 <span class="preprocessor">#endif</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="comment">// -----------------------------------------------------------------------------</span>
<a name="l00015"></a>00015 
<a name="l00016"></a>00016 <span class="comment">// // GenericClient opaque type.</span>
<a name="l00017"></a>00017 <span class="comment">// typedef struct GenericClient GenericClient;</span>
<a name="l00018"></a>00018 
<a name="l00019"></a>00019 <span class="comment">// the redundancy here is for doxygen documentation</span>
<a name="l00020"></a>00020 <span class="comment"></span>
<a name="l00021"></a>00021 <span class="comment">/// see GenericClient::genCli_close</span>
<a name="l00022"></a>00022 <span class="comment"></span><span class="keyword">extern</span> TC2API <span class="keywordtype">void</span> <a class="code" href="structGenericClient.html#a9f7b9a8d91772ca4e39b53be3d7025d1" title="Prepares the generic client for the CLOSE command.">genCli_close</a>(<span class="keywordtype">void</span>);
<a name="l00023"></a>00023 <span class="comment"></span>
<a name="l00024"></a>00024 <span class="comment">/// see Client::genCli_connect</span>
<a name="l00025"></a>00025 <span class="comment"></span><span class="keyword">extern</span> TC2API <span class="keywordtype">void</span> <a class="code" href="structGenericClient.html#a6878849f6f316f7166da090005d8a7f0" title="Prepares the generic client for the CONNECT command.">genCli_connect</a>(<span class="keywordtype">void</span>);
<a name="l00026"></a>00026 <span class="comment"></span>
<a name="l00027"></a>00027 <span class="comment">/// see Client::genCli_error</span>
<a name="l00028"></a>00028 <span class="comment"></span><span class="keyword">extern</span> TC2API <a class="code" href="config_8h.html#ab95f123a6c9bcfee6a343170ef8c5f69" title="unsigned short abbreviation">ushort</a> <a class="code" href="structGenericClient.html#a07c1d0aa56c47777fa2e989619efaad2" title="Retrieves the error that occurred last.">genCli_error</a>(<span class="keywordtype">void</span>);
<a name="l00029"></a>00029 <span class="comment"></span>
<a name="l00030"></a>00030 <span class="comment">/// see Client::genCli_errorType</span>
<a name="l00031"></a>00031 <span class="comment"></span><span class="keyword">extern</span> TC2API <a class="code" href="config_8h.html#ab95f123a6c9bcfee6a343170ef8c5f69" title="unsigned short abbreviation">ushort</a> <a class="code" href="structGenericClient.html#a66e36d0f39cf6035f288c85b941abe7e" title="Retrieves the type of the error that occurred last.">genCli_errorType</a>(<span class="keywordtype">void</span>);
<a name="l00032"></a>00032 <span class="comment"></span>
<a name="l00033"></a>00033 <span class="comment">/// see Client::genCli_event</span>
<a name="l00034"></a>00034 <span class="comment"></span><span class="keyword">extern</span> TC2API <a class="code" href="config_8h.html#ab95f123a6c9bcfee6a343170ef8c5f69" title="unsigned short abbreviation">ushort</a> <a class="code" href="structGenericClient.html#a789e3f5fa2a8c3f7f2970bbdbbdae23b" title="Retrieves the event that occurred last.">genCli_event</a>(<span class="keywordtype">void</span>);
<a name="l00035"></a>00035 <span class="comment"></span>
<a name="l00036"></a>00036 <span class="comment">/// see Client::genCli_init</span>
<a name="l00037"></a>00037 <span class="comment"></span><span class="keyword">extern</span> TC2API <span class="keywordtype">void</span> <a class="code" href="structGenericClient.html#a96874a54fc93a83624ce701000705885" title="initializes the generic client.">genCli_init</a>(<span class="keywordtype">void</span>);
<a name="l00038"></a>00038 <span class="comment"></span>
<a name="l00039"></a>00039 <span class="comment">/// see Client::genCli_message</span>
<a name="l00040"></a>00040 <span class="comment"></span><span class="keyword">extern</span> TC2API <a class="code" href="structMessage.html" title="Message data structure.">Message</a>* <a class="code" href="structGenericClient.html#a9fafb2baa5e3ab2fff76f5eb9261ad72" title="Retrieves the Message associated with the last event.">genCli_message</a>(<span class="keywordtype">void</span>);
<a name="l00041"></a>00041 <span class="comment"></span>
<a name="l00042"></a>00042 <span class="comment">/// see Client::genCli_operation</span>
<a name="l00043"></a>00043 <span class="comment"></span><span class="keyword">extern</span> TC2API <a class="code" href="config_8h.html#a0f128c3e0c83721af0220c00554e9c4e" title="const char abbreviation">cchar</a>* <a class="code" href="structGenericClient.html#a2261f758ce32920f17d1dacdf6af4dab" title="Retrieves the name of the last operation performed (for error reporting).">genCli_operation</a>(<span class="keywordtype">void</span>);
<a name="l00044"></a>00044 <span class="comment"></span>
<a name="l00045"></a>00045 <span class="comment">/// see Client::genCli_recv</span>
<a name="l00046"></a>00046 <span class="comment"></span><span class="keyword">extern</span> TC2API <span class="keywordtype">void</span> <a class="code" href="structGenericClient.html#ada17c034d6ef0a119ce68df7dda02313" title="Prepares the generic client for the RECV command.">genCli_recv</a>(<span class="keywordtype">void</span>);
<a name="l00047"></a>00047 <span class="comment"></span>
<a name="l00048"></a>00048 <span class="comment">/// see Client::genCli_send</span>
<a name="l00049"></a>00049 <span class="comment"></span><span class="keyword">extern</span> TC2API <span class="keywordtype">void</span> <a class="code" href="structGenericClient.html#a23da57feb26683c14ffedd0d649a22d1" title="Prepares the generic client for the SEND command.">genCli_send</a>(<span class="keywordtype">void</span>);
<a name="l00050"></a>00050 <span class="comment"></span>
<a name="l00051"></a>00051 <span class="comment">/// see Client::genCli_setRetryConnect</span>
<a name="l00052"></a>00052 <span class="comment"></span><span class="keyword">extern</span> TC2API <span class="keywordtype">void</span> <a class="code" href="structGenericClient.html#aeebcd777911db64a067bbccf031cae98" title="Configures the option for automatic retry when connecting to server.">genCli_setRetryConnect</a>(<span class="keywordtype">bool</span>);
<a name="l00053"></a>00053 <span class="comment"></span>
<a name="l00054"></a>00054 <span class="comment">/// see Client::genCli_waitEvent</span>
<a name="l00055"></a>00055 <span class="comment"></span><span class="keyword">extern</span> TC2API <a class="code" href="config_8h.html#ab95f123a6c9bcfee6a343170ef8c5f69" title="unsigned short abbreviation">ushort</a> <a class="code" href="structGenericClient.html#a796987c44cef7aa163f189b827610fac" title="Runs the generic client application and returns an event to the appilcation.">genCli_waitEvent</a>(<span class="keywordtype">void</span>);
<a name="l00056"></a>00056 <span class="comment"></span>
<a name="l00057"></a>00057 <span class="comment">/// see Client::ClientEventId</span>
<a name="l00058"></a><a class="code" href="GenericClient_8h.html#a0be5647fd0926a22950d6106991586bb">00058</a> <span class="comment"></span><span class="keyword">enum</span> <a class="code" href="GenericClient_8h.html#a0be5647fd0926a22950d6106991586bb" title="see Client::ClientEventId">ClientEventId</a>
<a name="l00059"></a>00059 {
<a name="l00060"></a><a class="code" href="GenericClient_8h.html#a0be5647fd0926a22950d6106991586bba6e08f7a76bef434b2172b6fb7346e7cc">00060</a>    <a class="code" href="GenericClient_8h.html#a0be5647fd0926a22950d6106991586bba6e08f7a76bef434b2172b6fb7346e7cc">CLI_EVT_CONNECTION_CREATED</a>   , <span class="comment">// connection has been created</span>
<a name="l00061"></a><a class="code" href="GenericClient_8h.html#a0be5647fd0926a22950d6106991586bba727593ffcb45fcdd349d6c239b73c170">00061</a>    <a class="code" href="GenericClient_8h.html#a0be5647fd0926a22950d6106991586bba727593ffcb45fcdd349d6c239b73c170">CLI_EVT_CONNECTION_DESTROYED</a> , <span class="comment">// connection has been destroyed</span>
<a name="l00062"></a><a class="code" href="GenericClient_8h.html#a0be5647fd0926a22950d6106991586bbaabb344ce999356eb156548c698e2fe5e">00062</a>    <a class="code" href="GenericClient_8h.html#a0be5647fd0926a22950d6106991586bbaabb344ce999356eb156548c698e2fe5e">CLI_EVT_CONNECT_ERROR</a>        , <span class="comment">// error when trying to connect</span>
<a name="l00063"></a><a class="code" href="GenericClient_8h.html#a0be5647fd0926a22950d6106991586bbaa2463a1940371976699eec52b492c430">00063</a>    <a class="code" href="GenericClient_8h.html#a0be5647fd0926a22950d6106991586bbaa2463a1940371976699eec52b492c430">CLI_EVT_RECV_COMPLETE</a>        , <span class="comment">// a complete message ahs arrived</span>
<a name="l00064"></a><a class="code" href="GenericClient_8h.html#a0be5647fd0926a22950d6106991586bbab397a1ba4584b4b35355eceb5f2c4b23">00064</a>    <a class="code" href="GenericClient_8h.html#a0be5647fd0926a22950d6106991586bbab397a1ba4584b4b35355eceb5f2c4b23">CLI_EVT_RECV_TIMEOUT</a>         , <span class="comment">// not one byte of a message arrived</span>
<a name="l00065"></a><a class="code" href="GenericClient_8h.html#a0be5647fd0926a22950d6106991586bba1b7016c33830495cb9d1564bbab8b95d">00065</a>    <a class="code" href="GenericClient_8h.html#a0be5647fd0926a22950d6106991586bba1b7016c33830495cb9d1564bbab8b95d">CLI_EVT_SEND_COMPLETE</a>        , <span class="comment">// a message was successfully sent</span>
<a name="l00066"></a><a class="code" href="GenericClient_8h.html#a0be5647fd0926a22950d6106991586bbab4e272b5a5358394f2a6100c42a0ec7d">00066</a>    <a class="code" href="GenericClient_8h.html#a0be5647fd0926a22950d6106991586bbab4e272b5a5358394f2a6100c42a0ec7d">CLI_EVT_INVALID_COMMAND</a>      , <span class="comment">// command (send, etc) invalid in the context</span>
<a name="l00067"></a>00067 };
<a name="l00068"></a>00068 <span class="comment"></span>
<a name="l00069"></a>00069 <span class="comment">/// see Client::ClientErrorType</span>
<a name="l00070"></a><a class="code" href="GenericClient_8h.html#a2fe51197a2b46d0a7f33c23780a69a22">00070</a> <span class="comment"></span><span class="keyword">enum</span> <a class="code" href="GenericClient_8h.html#a2fe51197a2b46d0a7f33c23780a69a22" title="see Client::ClientErrorType">ClientErrorType</a>
<a name="l00071"></a>00071 {
<a name="l00072"></a><a class="code" href="GenericClient_8h.html#a2fe51197a2b46d0a7f33c23780a69a22a4b3efe8841d8217f5e0880c3018555db">00072</a>    <a class="code" href="GenericClient_8h.html#a2fe51197a2b46d0a7f33c23780a69a22a4b3efe8841d8217f5e0880c3018555db">CLI_ERR_CONNECTION_CLOSED</a> = 1 ,  <span class="comment">// connection closed by server</span>
<a name="l00073"></a><a class="code" href="GenericClient_8h.html#a2fe51197a2b46d0a7f33c23780a69a22a049a549d70079d7d5e0f499be32183a5">00073</a>    <a class="code" href="GenericClient_8h.html#a2fe51197a2b46d0a7f33c23780a69a22a049a549d70079d7d5e0f499be32183a5">CLI_ERR_SOCKET_ERROR</a>          ,  <span class="comment">// socket error</span>
<a name="l00074"></a><a class="code" href="GenericClient_8h.html#a2fe51197a2b46d0a7f33c23780a69a22a14d6a37bb66be1c7aea4d346a48cd941">00074</a>    <a class="code" href="GenericClient_8h.html#a2fe51197a2b46d0a7f33c23780a69a22a14d6a37bb66be1c7aea4d346a48cd941">CLI_ERR_FORMAT_ERROR</a>          ,  <span class="comment">// invalid format on the wire</span>
<a name="l00075"></a><a class="code" href="GenericClient_8h.html#a2fe51197a2b46d0a7f33c23780a69a22a0574d8e023b3bc17d1fc72c4974df117">00075</a>    <a class="code" href="GenericClient_8h.html#a2fe51197a2b46d0a7f33c23780a69a22a0574d8e023b3bc17d1fc72c4974df117">CLI_ERR_TIMEOUT_SEND</a>          ,  <span class="comment">// server has froze, got stuck, etc</span>
<a name="l00076"></a><a class="code" href="GenericClient_8h.html#a2fe51197a2b46d0a7f33c23780a69a22a94bf00832fbc1517dbc939c285e87d16">00076</a>    <a class="code" href="GenericClient_8h.html#a2fe51197a2b46d0a7f33c23780a69a22a94bf00832fbc1517dbc939c285e87d16">CLI_ERR_FORCED_CLOSE</a>          ,  <span class="comment">// connection closed by application</span>
<a name="l00077"></a>00077 };
<a name="l00078"></a>00078 
<a name="l00079"></a>00079 <span class="comment">// -----------------------------------------------------------------------------</span>
<a name="l00080"></a>00080 <span class="preprocessor">#ifdef __cplusplus</span>
<a name="l00081"></a>00081 <span class="preprocessor"></span>} <span class="comment">// #ifdef __cplusplus</span>
<a name="l00082"></a>00082 <span class="preprocessor">#endif</span>
<a name="l00083"></a>00083 <span class="preprocessor"></span><span class="comment">// -----------------------------------------------------------------------------</span>
<a name="l00084"></a>00084 <span class="preprocessor">#endif // __GENERIC_CLIENT_H__</span>
<a name="l00085"></a>00085 <span class="preprocessor"></span><span class="comment">// -----------------------------------------------------------------------------</span>
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Sat May 8 16:16:36 2010 for TcpClient2 by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
zvx
Software Developer
Brazil Brazil
I'm a long-time software developer living in Brazil.

I've been developing software for retail and banking automation in C/C++ for many years now. In the old days I even did some COBOL programming, and some assembly for the 8080.

My experience ranges from low level software such as interface code for serial devices for DOS and Windows (bar code scanners, printers, cash dispensers, etc) and goes to writing end user applications for POS terminals and bank ATMs. In between I've done a great deal of TCP/IP programming using the basic Berkeley sockets interface, which is my main interest nowadays.

Comments and Discussions