资源简介
udp网络通信例子源代码(单播、组播、广播)

代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
int main(int argc char **argv)
{
char buff[512] = “---------> The message is from clinet! <----------“;
if (argc != 3)
{
printf(“Usage: %s server-ip port“ argv[0]);
exit(1);
}
printf(“This is a UDP client\n“);
struct sockaddr_in addr;
int sock;
if ( (sock=socket(AF_INET SOCK_DGRAM 0)) <0)
{
perror(“socket“);
exit(1);
}
addr.sin_family = AF_INET;
addr.sin_port = htons(atoi(argv[2]));
addr.sin_addr.s_addr = inet_addr(argv[1]);
if (addr.sin_addr.s_addr == INADDR_NONE)
{
printf(“Incorrect ip address!“);
close(sock);
exit(1);
}
int len = sizeof(addr);
while (1)
{
// gets(buff);
int n;
if( sendto(sock buff strlen(buff) 0 (struct sockaddr *)&addr sizeof(addr)) < 0){
perror(“sendto“);
close(sock);
break;
}else{
printf(“clinet send success!\n“);
}
n = recvfrom(sock buff 512 0 (struct sockaddr *)&addr &len);
if (n>0)
{
buff[n] = 0;
printf(“received %d bytes:“n);
puts(buff);
}
else if (n==0)
{
printf(“server closed\n“);
close(sock);
break;
}
else if (n == -1)
{
perror(“recvfrom“);
close(sock);
break;
}
}
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-11-22 16:39 udp网络通信\
目录 0 2013-11-22 16:39 udp网络通信\单播\
文件 1693 2013-11-21 16:10 udp网络通信\单播\udp_clinet.c
文件 1537 2013-11-21 15:42 udp网络通信\单播\udp_server.c
文件 181250 2013-11-22 16:02 udp网络通信\单播\udp单播.png
目录 0 2013-11-22 16:39 udp网络通信\广播\
文件 361 2012-09-14 15:38 udp网络通信\广播\Makefile
文件 3680 2012-09-14 18:05 udp网络通信\广播\bcast_client.c
文件 2552 2012-09-14 17:41 udp网络通信\广播\bcast_server.c
文件 91815 2013-11-22 16:32 udp网络通信\广播\udp广播.png
目录 0 2013-11-22 16:39 udp网络通信\组播\
文件 2571 2013-11-22 17:55 udp网络通信\组播\multi_udp_clinet.c
文件 2875 2013-11-21 10:13 udp网络通信\组播\multi_udp_server.c
文件 76608 2013-11-22 16:29 udp网络通信\组播\udp组播.png
- 上一篇:图书管理系统毕业论文开题报告 中期报告 完整论文
- 下一篇:GPS接收程序
相关资源
- Visio图标-最新最全的网络通信图标库
- uboot到linux logo显示不间断 补丁
- UNIX/LINUX编程实践教程的源码
- 使用选择性重传协议实现UDP可靠通信
- Linux任务管理器
- linux应用层的华容道游戏源代码
- ubuntu9.10 可加载内核模块和字符设备驱
- MP3文件ID3v2ID3v2APEv2标签读取
- 防火墙编程-Visual C 网络通信开发
- 操作系统实验——虚存管理实验
- linux下的发包工具sendip
- 尚观培训linux许巍关于c 的笔记和讲义
- 尚观培训linux董亮老师关于数据结构的
- linux 线程池源码 c 版
- linux C 电梯程序练习
- 网络(UDP)转串口程序
- linux下用多进程同步方法解决生产者
- Linux 操作系统实验(全)
- Linux From Scratch 中文手册
- linux 网络实验 ftp程序
- 用Socket写的简易FTP服务器和客户端
- Linux命令大全离线版&在线版
- 操作系统共享内存实验
- dos 下运行Linux 命令--gnu_utils
- linux 0.12内核源代码
- linux简易shell C实现
- linux实验报告及心得体会
- 基于GTK的Linux环境下的简易任务管理器
- socket小工具(可方便建立TCP UDP的soc
- UDP组播的发送和接收程序
评论
共有 条评论