tcpcmain.c

来自「DOS下的TCP/IP源代码,可以做参考.」· C语言 代码 · 共 41 行

C
41
字号
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <time.h>
#include <bios.h>
#include <dos.h>
#include "tcplib.h"

//========================================================
int client(char *host,int port)
{ char buf[1030],buf1[1030];
  int l;
  TCPSocket hl;
  hl=new_socket();
  if (connect_tcp(hl,host,port)!=1)
  {printf("Can't locate the HTTP server(%s)\n",host);
   release_socket(hl);
   return 0;
  }

  sprintf(buf,"Hi, This is a test of TCP Client.");
  write_tcp(hl,buf,strlen(buf),10);
  l=read_tcp_time(hl,buf1,1024,2);
  buf1[l]=0;
  printf("Received: %s\n",buf1);

  disconnect_tcp(hl);
  release_socket(hl);
  return 1;
}


int main(void)
{ char *server="202.114.6.48";
  int port=6666;
  init_tcplib();
  client(server,port);
  return 0;
}

⌨️ 快捷键说明

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