udpcmain.c

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

C
28
字号
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <dos.h>
#include "tcplib.h"
//=======================================================================
int main(void)
{UDPSocket sendSock;
 int port,len;
 char sendBuff[1024],buf[256],ip[32];
 printf("\nUDP Client\n");
 port=8888;
 strcpy(ip,"202.114.6.48");
 sendSock=new_udpsocket();
 init_tcplib();
 open_udp(sendSock,ip,port);
 sprintf(sendBuff, "This is a test: sending packet \n");
 udp_send(sendSock,sendBuff,strlen(sendBuff));
 len=udp_recv_time(sendSock,buf,256,2);
 buf[len]=0;
 close_udp(sendSock);
 printf("Receive: %s\n",buf);
 release_udpsocket(sendSock);
 return 0;
}

⌨️ 快捷键说明

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