📄 tcpdmain.c
字号:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <dos.h>
#include "tcplib.h"
//================================================
extern char tcpdebug;
extern long int tcptime;
TCPSocket tcphl;
//================================================
void ServeTcp(void)
{int len;
char buf[512],buf1[512];
while (tcp_kernal(tcphl))
{len=0;
if (peer_tcp_data(tcphl))
{len=read_tcp(tcphl,buf,500);
buf[len]=0;
printf("\n%s",buf);
}
if (len>0)
{strcpy(buf1,"TCP Server for DOS");
write_tcp(tcphl,buf1,strlen(buf1),10);
close_tcp_socket(tcphl);
return;
}
}
return;
}
//=============================================================
void starttcp(void)
{printf("\nTCP Server for DOS -- He Lingsong, 1/3/2001\n");
tcphl=new_socket();
listen_tcp(tcphl,21);
}
void releasetcp(void)
{if (tcphl!=NULL) {close_tcp_socket(tcphl);}
delay(100);
if (tcphl!=NULL) release_socket(tcphl);
}
int checktcp(void)
{if (!tcp_kernal(tcphl)) //create Listen
{listen_tcp(tcphl,21);return 0;}
if (open_success_tcp(tcphl)) return 1;
return 0;
}
//========================================================
int main(void)
{int rc;
init_tcplib();
starttcp();
while (1)
{if (kbhit())
if (getch() == 27)
{releasetcp();
return 0;
}
rc=checktcp(); //Monitoring FTP user login
if (rc==1) ServeTcp();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -