⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcp__server__demo_8c-source.html

📁 Freescale mcu OpenTCP-1.0.4.doc.html.zip 文档
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>/opentcp/demo/tcp_server_demo.c Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="main.html">Main Page</a> &nbsp; <a class="qindex" href="modules.html">Modules</a> &nbsp; <a class="qindex" href="annotated.html">Data Structures</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Data Fields</a> &nbsp; <a class="qindex" href="globals.html">Globals</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindex" href="examples.html">Examples</a> &nbsp; </center><hr><h1>/opentcp/demo/tcp_server_demo.c</h1><a href="tcp__server__demo_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*</span>00002 <span class="comment"> *Copyright (c) 2000-2002 Viola Systems Ltd.</span>00003 <span class="comment"> *All rights reserved.</span>00004 <span class="comment"> *</span>00005 <span class="comment"> *Redistribution and use in source and binary forms, with or without </span>00006 <span class="comment"> *modification, are permitted provided that the following conditions </span>00007 <span class="comment"> *are met:</span>00008 <span class="comment"> *</span>00009 <span class="comment"> *1. Redistributions of source code must retain the above copyright </span>00010 <span class="comment"> *notice, this list of conditions and the following disclaimer.</span>00011 <span class="comment"> *</span>00012 <span class="comment"> *2. Redistributions in binary form must reproduce the above copyright </span>00013 <span class="comment"> *notice, this list of conditions and the following disclaimer in the </span>00014 <span class="comment"> *documentation and/or other materials provided with the distribution.</span>00015 <span class="comment"> *</span>00016 <span class="comment"> *3. The end-user documentation included with the redistribution, if </span>00017 <span class="comment"> *any, must include the following acknowledgment:</span>00018 <span class="comment"> *      "This product includes software developed by Viola </span>00019 <span class="comment"> *      Systems (http://www.violasystems.com/)."</span>00020 <span class="comment"> *</span>00021 <span class="comment"> *Alternately, this acknowledgment may appear in the software itself, </span>00022 <span class="comment"> *if and wherever such third-party acknowledgments normally appear.</span>00023 <span class="comment"> *</span>00024 <span class="comment"> *4. The names "OpenTCP" and "Viola Systems" must not be used to </span>00025 <span class="comment"> *endorse or promote products derived from this software without prior </span>00026 <span class="comment"> *written permission. For written permission, please contact </span>00027 <span class="comment"> *opentcp@opentcp.org.</span>00028 <span class="comment"> *</span>00029 <span class="comment"> *5. Products derived from this software may not be called "OpenTCP", </span>00030 <span class="comment"> *nor may "OpenTCP" appear in their name, without prior written </span>00031 <span class="comment"> *permission of the Viola Systems Ltd.</span>00032 <span class="comment"> *</span>00033 <span class="comment"> *THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED </span>00034 <span class="comment"> *WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF </span>00035 <span class="comment"> *MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. </span>00036 <span class="comment"> *IN NO EVENT SHALL VIOLA SYSTEMS LTD. OR ITS CONTRIBUTORS BE LIABLE </span>00037 <span class="comment"> *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR </span>00038 <span class="comment"> *CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF </span>00039 <span class="comment"> *SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR </span>00040 <span class="comment"> *BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, </span>00041 <span class="comment"> *WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE </span>00042 <span class="comment"> *OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, </span>00043 <span class="comment"> *EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>00044 <span class="comment"> *====================================================================</span>00045 <span class="comment"> *</span>00046 <span class="comment"> *OpenTCP is the unified open source TCP/IP stack available on a series </span>00047 <span class="comment"> *of 8/16-bit microcontrollers, please see &lt;http://www.opentcp.org&gt;.</span>00048 <span class="comment"> *</span>00049 <span class="comment"> *For more information on how to network-enable your devices, or how to </span>00050 <span class="comment"> *obtain commercial technical support for OpenTCP, please see </span>00051 <span class="comment"> *&lt;http://www.violasystems.com/&gt;.</span>00052 <span class="comment"> */</span>00053 00072 <span class="preprocessor">#include &lt;<a class="code" href="debug_8h.html">inet/debug.h</a>&gt;</span>00073 <span class="preprocessor">#include &lt;<a class="code" href="datatypes_8h.html">inet/datatypes.h</a>&gt;</span>00074 <span class="preprocessor">#include &lt;<a class="code" href="globalvariables_8h.html">inet/globalvariables.h</a>&gt;</span>00075 <span class="preprocessor">#include &lt;<a class="code" href="system_8h.html">inet/system.h</a>&gt;</span>00076 <span class="preprocessor">#include &lt;<a class="code" href="tcp__ip_8h.html">inet/tcp_ip.h</a>&gt;</span>00077 00078 00079 00080 <span class="comment">/* The applications that use TCP must implement following function stubs                        */</span>00081 <span class="comment">/* void application_name_init (void) - call once when processor starts                          */</span>00082 <span class="comment">/* void application_name_run (void) - call periodically on main loop                            */</span>00083 <span class="comment">/* INT32 application_name_eventlistener (INT8, UINT8, UINT32, UINT32)                           */</span>00084 <span class="comment">/* - called by TCP input process to inform arriving data, errors etc */</span>00085 00086 <span class="comment">/* These will probably go to some include file */</span>00087 <span class="keywordtype">void</span> tcps_demo_init(<span class="keywordtype">void</span>);00088 <span class="keywordtype">void</span> tcps_demo_run(<span class="keywordtype">void</span>);00089 INT32 tcps_demo_eventlistener(INT8 , UINT8 , UINT32 , UINT32 );00090 <a name="l00098"></a><a class="code" href="tcp__server__demo_8c.html#a1">00098</a> INT8 <a class="code" href="tcp__server__demo_8c.html#a1">tcps_demo_soch</a>;00099 <a name="l00100"></a><a class="code" href="tcp__server__demo_8c.html#a2">00100</a> UINT8 <a class="code" href="tcp__server__demo_8c.html#a2">tcps_demo_senddata</a>; <a name="l00102"></a><a class="code" href="tcp__server__demo_8c.html#a0">00102</a> <span class="preprocessor">#define TCPS_DEMO_PORT  5001 </span>00104 <span class="preprocessor"></span><span class="comment">/* Internal function used for sending data to a predefined host */</span>00105 INT16 tcps_demo_send(<span class="keywordtype">void</span>);00106 00107 <span class="comment">/* Initialize resources needed for the TCP server application */</span>00108 <span class="keywordtype">void</span> tcps_demo_init(<span class="keywordtype">void</span>)00109 {00110         00111         DEBUGOUT(<span class="stringliteral">"Initializing TCP server application. \r\n"</span>);00112                 00113         <span class="comment">/* Get socket:</span>00114 <span class="comment">         *      TCP_TYPE_SERVER - type of TCP socket is server</span>00115 <span class="comment">         *      TCP_TOS_NORMAL  - no other type of service implemented so far</span>00116 <span class="comment">         *      TCP_DEF_TOUT    - timeout value in seconds. If for this many seconds</span>00117 <span class="comment">         *              no data is exchanged over the TCP connection the socket will be</span>00118 <span class="comment">         *              closed.</span>00119 <span class="comment">         *      tcps_demo_eventlistener - pointer to event listener function for</span>00120 <span class="comment">         *              this socket.    </span>00121 <span class="comment">         */</span>00122 00123         <a class="code" href="tcp__server__demo_8c.html#a1">tcps_demo_soch</a> = <a class="code" href="tcp_8c.html#a3">tcp_getsocket</a>(<a class="code" href="tcp__ip_8h.html#a39">TCP_TYPE_SERVER</a>, <a class="code" href="tcp__ip_8h.html#a18">TCP_TOS_NORMAL</a>, <a class="code" href="group__opentcp__config.html#a14">TCP_DEF_TOUT</a>, tcps_demo_eventlistener);00124         00125         <span class="keywordflow">if</span>( <a class="code" href="tcp__server__demo_8c.html#a1">tcps_demo_soch</a> &lt; 0 )00126         {00127                 DEBUGOUT(<span class="stringliteral">"TCP server unable to get socket. Resetting!!!\r\n"</span>);00128                 <a class="code" href="system_8h.html#a6">RESET_SYSTEM</a>();00129         }00130         00131         <span class="comment">/* Put it to listen on some port        */</span>00132         <a class="code" href="tcp_8c.html#a5">tcp_listen</a>(<a class="code" href="tcp__server__demo_8c.html#a1">tcps_demo_soch</a>,<a class="code" href="tcp__server__demo_8c.html#a0">TCPS_DEMO_PORT</a>);00133         00134         <span class="comment">/* for now no data sending */</span>00135         <a class="code" href="tcp__server__demo_8c.html#a2">tcps_demo_senddata</a>=0;00136 }00137 00138 <span class="keywordtype">void</span> tcps_demo_run(<span class="keywordtype">void</span>)00139 {00140         00141         UINT8   i;00142         00143         <span class="comment">/* do maybe some other TCP server app stuff</span>00144 <span class="comment">         * .....</span>00145 <span class="comment">         */</span>00146         00147         <span class="keywordflow">if</span>(tcps_demo_senddata){00148                 <span class="keywordflow">if</span>(tcps_demo_send()!=-1)                00149                         <a class="code" href="tcp__server__demo_8c.html#a2">tcps_demo_senddata</a>=0;00150         }00151 }00152 00153  <span class="comment">/*</span>00154 <span class="comment"> * Event listener invoked when TCP/IP stack receives TCP data for</span>00155 <span class="comment"> * a given socket. Parameters:</span>00156 <span class="comment"> * - cbhandle - handle of the socket this packet is intended for. Check it</span>00157 <span class="comment"> *      just to be sure, but in general case not needed</span>00158 <span class="comment"> * - event - event that is notified. For TCP there are quite a few possible</span>00159 <span class="comment"> *      events, check switch structure below for more information</span>00160 <span class="comment"> * - par1, par2 - parameters who's use depends on the event that is notified</span>00161 <span class="comment"> */</span>00162 INT32 tcps_demo_eventlistener(INT8 cbhandle, UINT8 event, UINT32 par1, UINT32 par2)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -