资源简介
中南大学通信工程课内实验:SOCKET通信。环回测试。使用UDP协议参数,由程序自动地循环发送“数字 1”至“数字 100”。
进行两台计算机之间的通信。

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#define PORT 1111
#define MAXDATASIZE 100
int main (int argc char *argv[]) {
int fd numbytes;
char buf[MAXDATASIZE];
struct hostent *he;
struct sockaddr_in server reply;
if (argc != 2) {
printf(“Usage: %s\n“ argv[0]);
exit(1);
}
if ( (he = gethostbyname(argv[1])) == NULL) {
printf(“gethostbyname error!“);
exit(1);
}
if ( (fd = socket(AF_INET SOCK_DGRAM 0)) == -1) {
printf(“socket() error\n“);
exit(1);
}
bzero(&server sizeof(server));
server.sin_family = AF_INET;
server.sin_port = htons(PORT);
server.sin_addr = *((struct in_addr *)he->h_addr);
int len;
char a[2];
for (int i = 1; i <= 100; i++) {
sprintf(a “%d“ i);
sendto(fd a 2 0 (struct sockaddr *)&server sizeof(struct sockaddr));
if ( (numbytes = recvfrom(fd buf MAXDATASIZE 0 (struct sockaddr *)&server &len)) == -1) {
printf(“recvfrom() error\n“);
exit(1);
}
buf[numbytes] = ‘\0‘;
printf(“%s\n“ buf);
}
close(fd);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-12-09 09:22 UDP\
文件 12880 2018-12-07 09:22 UDP\Client
文件 13000 2018-12-07 09:22 UDP\Server
文件 1106 2018-12-07 09:21 UDP\udpClient.c
文件 1124 2018-12-07 09:22 UDP\udpServer.c
相关资源
- 使用选择性重传协议实现UDP可靠通信
- 网络(UDP)转串口程序
- 用Socket写的简易FTP服务器和客户端
- socket小工具(可方便建立TCP UDP的soc
- UDP组播的发送和接收程序
- 采用WINSOCK2 编写的TCP/UDP通信程序
- TCP_UDP对结构体加密数据传输
- 欧姆龙以太网通讯TCP/UDP及欧姆龙PLC程
- UDP协议进行P2P打洞
- 计算机网络socket编程实验
- UDP P2P打洞服务器
- 一个老外写的RUDP的源代码
- udp丢包率统计
- Socket-UDP整合消息接收,发送
- 基于qt的udp实时录音
- 真正的Delphi点对点UDP通讯
- TCPUDPDbg一个好用的tcp/udp工具
- 值得看的Delphi点对点UDP通讯.rar
- tcp udp debug
- unix网络编程英文版第三版pdf
- 安卓手机socket通信服务端和客户端
- QT开发的串口udptcp通信上位机软件
- go语言实现udp server和MongoDB数据写入
- lwip+udp项目
- UDPSender.rar
- 智能家居UDP通信
- QT下写的界面程序,可以实现串口和
- sokit TCP/UDP 数据包收发测试(调试)工
- Labwindow_cvi TCP UDP通信例程
- udp滑动窗口流量控制完美实现
评论
共有 条评论