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

📄 tcpdsample.htm

📁 tcpip for dos
💻 HTM
字号:
<HTML><HEAD><TITLE>DOS Internet Programming APIs</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="He Lingsong" name=Author>
<META content="MSHTML 6.00.2600.0" name=GENERATOR>
<META content=DOS,FTP,HTTP,email,smtp,web,www,server,tcp,wattcp,free 
name=KeyWords></HEAD>
<BODY><B><FONT color=#cc0000>TCP服务器程序样例:</FONT></B> 
<BLOCKQUOTE><FONT color=#006600>#include &lt;stdio.h&gt;</FONT> <BR><FONT 
  color=#006600>#include &lt;string.h&gt;</FONT> <BR><FONT 
  color=#006600>#include &lt;conio.h&gt;</FONT> <BR><FONT color=#006600>#include 
  &lt;ctype.h&gt;</FONT> <BR><FONT color=#006600>#include &lt;dos.h&gt;</FONT> 
  <BR><FONT color=#006600>#include "tcplib.h"</FONT><FONT color=#006600></FONT> 
  <P><FONT 
  color=#006600>//================================================</FONT> 
  <BR><FONT color=#006600>extern char tcpdebug;</FONT> <BR><FONT 
  color=#006600>extern long int tcptime;</FONT> <BR><FONT 
  color=#006600>TCPSocket tcphl;</FONT> <BR><FONT 
  color=#006600>//================================================</FONT><FONT 
  color=#006600></FONT> 
  <P><FONT color=#006600>void ServeTcp(void)</FONT> <BR><FONT color=#006600>{int 
  len;</FONT> <BR><FONT color=#006600>&nbsp;char buf[512],buf1[512];</FONT><FONT 
  color=#006600></FONT> 
  <P><FONT color=#006600>&nbsp;while (tcp_kernal(tcphl))</FONT> <BR><FONT 
  color=#006600>&nbsp;&nbsp; {len=0;</FONT> <BR><FONT 
  color=#006600>&nbsp;&nbsp;&nbsp; if (peer_tcp_data(tcphl))</FONT> <BR><FONT 
  color=#006600>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  {len=read_tcp(tcphl,buf,500);</FONT> <BR><FONT 
  color=#006600>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; buf[len]=0;</FONT> 
  <BR><FONT color=#006600>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  printf("\n%s",buf);</FONT> <BR><FONT 
  color=#006600>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</FONT> <BR><FONT 
  color=#006600>&nbsp;&nbsp;&nbsp; if (len&gt;0)</FONT> <BR><FONT 
  color=#006600>&nbsp;&nbsp;&nbsp;&nbsp; {strcpy(buf1,"TCP Server for 
  DOS");</FONT> <BR><FONT color=#006600>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  write_tcp(tcphl,buf1,strlen(buf1),10);</FONT> <BR><FONT 
  color=#006600>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; close_tcp_socket(tcphl);</FONT> 
  <BR><FONT color=#006600>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;</FONT> 
  <BR><FONT color=#006600>&nbsp;&nbsp;&nbsp;&nbsp; }</FONT> <BR><FONT 
  color=#006600>&nbsp; }</FONT> <BR><FONT color=#006600>&nbsp;return;</FONT> 
  <BR><FONT color=#006600>}</FONT><FONT color=#006600></FONT> 
  <P><FONT 
  color=#006600>//=============================================================</FONT> 
  <BR><FONT color=#006600>void starttcp(void)</FONT> <BR><FONT 
  color=#006600>{printf("\nTCP Server for DOS&nbsp; --&nbsp; He Lingsong, 
  1/3/2001\n");</FONT> <BR><FONT color=#006600>&nbsp;tcphl=new_socket();</FONT> 
  <BR><FONT color=#006600>&nbsp;listen_tcp(tcphl,6666);</FONT> <BR><FONT 
  color=#006600>}</FONT><FONT color=#006600></FONT> 
  <P><FONT color=#006600>void releasetcp(void)</FONT> <BR><FONT 
  color=#006600>{if (tcphl!=NULL) {close_tcp_socket(tcphl);}</FONT> <BR><FONT 
  color=#006600>&nbsp;delay(100);</FONT> <BR><FONT color=#006600>&nbsp;if 
  (tcphl!=NULL) release_socket(tcphl);</FONT> <BR><FONT 
  color=#006600>}</FONT><FONT color=#006600></FONT> 
  <P><FONT color=#006600>int checktcp(void)</FONT> <BR><FONT color=#006600>{if 
  (!tcp_kernal(tcphl))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  //create Listen</FONT> <BR><FONT color=#006600>&nbsp;&nbsp; 
  {listen_tcp(tcphl,6666);return 0;}</FONT> <BR><FONT color=#006600>&nbsp;if 
  (open_success_tcp(tcphl)) return 1;</FONT> <BR><FONT 
  color=#006600>&nbsp;return 0;</FONT> <BR><FONT color=#006600>}</FONT><FONT 
  color=#006600></FONT> 
  <P><FONT 
  color=#006600>//========================================================</FONT> 
  <BR><FONT color=#006600>int main(void)</FONT> <BR><FONT color=#006600>{int 
  rc;</FONT> <BR><FONT color=#006600>&nbsp;init_tcplib();</FONT> <BR><FONT 
  color=#006600>&nbsp;starttcp();</FONT><FONT color=#006600></FONT> 
  <P><FONT color=#006600>&nbsp;while (1)</FONT> <BR><FONT color=#006600>&nbsp; 
  {if (kbhit())</FONT> <BR><FONT color=#006600>&nbsp;&nbsp;&nbsp; if (getch() == 
  27)</FONT> <BR><FONT color=#006600>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  {releasetcp();</FONT> <BR><FONT 
  color=#006600>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;</FONT> <BR><FONT 
  color=#006600>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</FONT> <BR><FONT 
  color=#006600>&nbsp;&nbsp; 
  rc=checktcp();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  //Monitoring FTP user login</FONT> <BR><FONT color=#006600>&nbsp;&nbsp; if 
  (rc==1) ServeTcp();</FONT> <BR><FONT color=#006600>&nbsp; }</FONT> <BR><FONT 
  color=#006600>}</FONT></P></BLOCKQUOTE><B><FONT 
color=#cc0000></FONT></B><BR><B><FONT color=#cc0000></FONT></B>&nbsp; 
<BLOCKQUOTE> <BR>&nbsp;</BLOCKQUOTE> </BODY></HTML>

⌨️ 快捷键说明

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