📄 client_8cc-source.html
字号:
<!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>client.cc Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body bgcolor="#ffffff"><!-- Generated by Doxygen 1.2.13.1 --><h1>client.cc</h1><a href="client_8cc.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 00034 <font class="preprocessor">#include <sys/time.h></font>00035 <font class="preprocessor">#include <iostream.h></font>00036 <font class="preprocessor">#include <string.h></font>00037 <font class="preprocessor">#include <stdlib.h></font>00038 <font class="preprocessor">#include <assert.h></font>00039 <font class="preprocessor">#include <unistd.h></font>00040 <font class="preprocessor">#include "<a class="code" href="const_8h.html">const.h</a>"</font>00041 <font class="preprocessor">#include "<a class="code" href="client_8h.html">client.h</a>"</font>00042 00043 <a name="l00044"></a><a class="code" href="client_8cc.html#a0">00044</a> <font class="keyword">extern</font> <font class="keywordtype">int</font> <a class="code" href="client_8cc.html#a0">errno</a>;<a name="l00045"></a><a class="code" href="client_8cc.html#a1">00045</a> <font class="keyword">extern</font> <font class="keywordtype">char</font>* <a class="code" href="client_8cc.html#a1">sys_errlist</a>[];00046 00047 <a name="l00048"></a><a class="code" href="classclient.html#a0">00048</a> <a class="code" href="classclient.html#a0">client :: client</a> () : <a class="code" href="classtcpip.html">tcpip</a> ()00049 {00050 <a class="code" href="classclient.html#o0">recived</a> = NULL;00051 }00052 <a name="l00053"></a><a class="code" href="classclient.html#a1">00053</a> <a class="code" href="classclient.html#a1">client :: ~client</a> ()00054 {00055 <font class="keywordflow">if</font> (<a class="code" href="classclient.html#o0">recived</a> != NULL)00056 <font class="keyword">delete</font> <a class="code" href="classclient.html#o0">recived</a>;00057 }00058 00059 <a name="l00060"></a><a class="code" href="classclient.html#b1">00060</a> <font class="keywordtype">void</font> <a class="code" href="classclient.html#b1">client :: send</a> (<font class="keywordtype">char</font>* host, <font class="keywordtype">char</font>* service, <font class="keywordtype">char</font>* packet)00061 {00062 <font class="keywordtype">int</font> sock;00063 sock = <a class="code" href="classtcpip.html#b1">connectUDP</a> (host, service);00064 (void) write (sock, packet, strlen (packet));00065 close (sock);00066 }00067 <a name="l00068"></a><a class="code" href="classclient.html#b2">00068</a> <font class="keywordtype">bool</font> <a class="code" href="classclient.html#b2">client :: recive</a> (<font class="keywordtype">char</font>* host, <font class="keywordtype">char</font>* service, <font class="keywordtype">char</font>* packet)00069 {00070 <font class="keywordtype">char</font> buff[2048];00071 buff[1] = <font class="charliteral">'\0'</font>;00072 <font class="keywordtype">int</font> sock;00073 <font class="keywordtype">int</font> length;00074 sock = <a class="code" href="classtcpip.html#b1">connectUDP</a> (host, service);00075 write (sock, packet, strlen (packet));00076 <font class="comment">/*</font>00077 <font class="comment"> fd_set rfds;</font>00078 <font class="comment"> struct timeval tv;</font>00079 <font class="comment"> tv.tv_sec = 3;</font>00080 <font class="comment"> tv.tv_usec = 0;</font>00081 <font class="comment"> FD_ZERO (&rfds);</font>00082 <font class="comment"> FD_SET (sock, &rfds);</font>00083 <font class="comment"> int a = select (1, &rfds, NULL, NULL, &tv);</font>00084 <font class="comment"> if (a == 0)</font>00085 <font class="comment"> {</font>00086 <font class="comment"> cerr << _NET_ERR_ << "read failed: Socket Timeout\n";</font>00087 <font class="comment"> return false;</font>00088 <font class="comment"> }</font>00089 <font class="comment"> if (a < 0)</font>00090 <font class="comment"> {</font>00091 <font class="comment"> cerr << _NET_ERR_ << "select failed: " << sys_errlist [errno] << "\n";</font>00092 <font class="comment"> return false;</font>00093 <font class="comment"> }</font>00094 <font class="comment">*/</font>00095 length = read (sock, buff, <font class="keyword">sizeof</font> (buff));00096 close (sock);00097 <font class="keywordflow">if</font> (length < 0)00098 {00099 cerr << <a class="code" href="const_8h.html#a0">_NET_ERR_</a> << <font class="stringliteral">"read failed: "</font> << <a class="code" href="client_8cc.html#a1">sys_errlist</a> [<a class="code" href="client_8cc.html#a0">errno</a>] << <font class="stringliteral">"\n"</font>;00100 <font class="keywordflow">return</font> <font class="keyword">false</font>;00101 }00102 buff[length] = <font class="charliteral">'\0'</font>;00103 <font class="keywordflow">if</font> (<a class="code" href="classclient.html#o0">recived</a> != NULL)00104 <font class="keyword">delete</font> <a class="code" href="classclient.html#o0">recived</a>;00105 <a class="code" href="classclient.html#o0">recived</a> = NULL;00106 <a class="code" href="classclient.html#o0">recived</a> = <font class="keyword">new</font> <font class="keywordtype">char</font> [length+1];00107 assert (<a class="code" href="classclient.html#o0">recived</a> != NULL);00108 strcpy (<a class="code" href="classclient.html#o0">recived</a>, buff);00109 <font class="keywordflow">return</font> <font class="keyword">true</font>;00110 }00111 <a name="l00112"></a><a class="code" href="classclient.html#b0">00112</a> <font class="keywordtype">char</font>* <a class="code" href="classclient.html#b0">client :: get_recived</a> ()00113 {00114 <font class="keywordflow">return</font> <a class="code" href="classclient.html#o0">recived</a>;00115 }00116 </pre></div><hr><address><small>© 2002 Marcin Caban 'Cabko' and Borys Wisniewski 'Boria'</small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -