资源简介
Vxworks下UDP收发与组播收发例程源码,也可用于Linux或者其它平台。
![](http://www.nz998.com/pic/35777.jpg)
代码片段和文件信息
#include “vxWorks.h“
#include “sockLib.h“
#include “inetLib.h“
#include “stdioLib.h“
#include “strLib.h“
#include “ioLib.h“
#include “fioLib.h“
#include “UDP.h“
int sFd = 0; /* Socket描述符 */
/****************************************
函数名称:void InitUdpSocket()
返回值:无
入参: 无
函数描述:初始化Udp的Socket具体包含以下操作:
1、创建Socket;
2、绑定Server端的地址。
****************************************/
void InitUdpSocket()
{
struct sockaddr_in LocalAddr; /* 服务器端的socket地址信息*/
int sockAddrSize; /* size of socket address structure */
/* 初始化地址 */
sockAddrSize = sizeof (struct sockaddr_in);
bzero ((char *) &LocalAddr sockAddrSize);
LocalAddr.sin_len = (u_char) sockAddrSize;
LocalAddr.sin_family = AF_INET;
LocalAddr.sin_port = htons (5500);
//LocalAddr.sin_addr.s_addr = htonl (INADDR_ANY);
LocalAddr.sin_addr.s_addr = inet_addr (“192.168.3.235“);
/* 创建Socket */
if((sFd = socket(AF_INETSOCK_DGRAM0)) == ERROR)
{
printf(“\r\n[ERROR]:socket() error in InitUdpSocket()!“);
}
#if 1
/* bind socket to local address */
if (bind (sFd (struct sockaddr *)&LocalAddr sockAddrSize) == ERROR)
{
printf(“\r\n[ERROR]:bind() error in InitUdpSocket()!“);
close (sFd);
}
#endif
#if 0
if(setsockopt(sFd IPPROTO_IP IP_MULTICAST_IF (char *)&LocalAddr sizeof(LocalAddr)) == ERROR)
{
printf(“First Setsockopt Error!\n“);
}
else
{
printf(“First Setsockopt Ok!\n“);
}
#endif
}
/****************************************
STATUS udpServer (UINT8 *pRcvDataUINT32 RcvDataLenUINT32 Port)
返回值:ERROR ---接收失败; 非ERROR ---接收成功,接收到的字节个数
入参:pRcvData ---接收到的数据指针
Port ---接收的端口号
函数描述:Udp的接收函数
****************************************/
STATUS udpServer (UINT8 *pRcvDataUINT32 Port)
{
struct sockaddr_in clientAddr; /* 客户端的socket地址信息 */
int sockAddrSize; /* size of socket address structure */
int Ret = 0;
bzero((UINT8*)&clientAddr sizeof(clientAddr));
sockAddrSize = sizeof(clientAddr);
Ret = recvfrom (sFdpRcvData10240(struct sockaddr *)&clientAddr&sockAddrSize);
if(Ret == ERROR)
{
printf(“\r\n[ERROR]:recvfrom() error!“);
close (sFd);
return (ERROR);
}
return (Ret);
}
/****************************************
函数名称:STATUS udpClient(char * serverNameUINT16 Port UINT8* sndDataUINT32 lenth)
返回值:0 ---发送成功; 非0 ---发送失败
入参:serverName ---接收端(Server)的IP地址
Port ---端口号
sndData ---要发送数据的指针
lenth ---要发送的数据字节个数
函数描述:Udp的发送函数
****************************************/
STATUS udpClient(char * serverNameUINT16 Port UINT8* sndDataUINT32 lenth)
{
struct sockaddr_in serverAddr; /* server‘s socket address */
int
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 9304 2018-07-16 20:17 udp\UDP.c
文件 301 2015-10-10 15:31 udp\UDP.h
目录 0 2018-07-03 13:47 udp
----------- --------- ---------- ----- ----
9605 3
- 上一篇:zkui-2.0 zookeeper可视化管理器
- 下一篇:WEBRTC多人视频通话
相关资源
- 使用选择性重传协议实现UDP可靠通信
- 网络(UDP)转串口程序
- 用Socket写的简易FTP服务器和客户端
- VxWorks TCPIP协议栈
- socket小工具(可方便建立TCP UDP的soc
- UDP组播的发送和接收程序
- 采用WINSOCK2 编写的TCP/UDP通信程序
- Win7下安装Tornado2.2vxWorks5.5的方法
- Vxworks下网卡驱动程序的开发
- TCP_UDP对结构体加密数据传输
- 欧姆龙以太网通讯TCP/UDP及欧姆龙PLC程
- zynq-7000-vxworks-bsp.zip
- UDP协议进行P2P打洞
- Vxworks6.8 SMP编程指导
- 《基于VXWorks的嵌入式系统及实验》
- 计算机网络socket编程实验
- VxWorks + Workbench开发
- UDP P2P打洞服务器
- 中兴通讯IPTV组播方案
- 一个老外写的RUDP的源代码
- 02_VxWorks7_开发环境Workbench介绍.pdf
- udp丢包率统计
- Socket-UDP整合消息接收,发送
- 基于qt的udp实时录音
- 真正的Delphi点对点UDP通讯
- TCPUDPDbg一个好用的tcp/udp工具
- 值得看的Delphi点对点UDP通讯.rar
- 跨AS 的源特定组播网络技术Juniper 网络
- tcp udp debug
- VxWorks5 5 1源代码 完整源代码
评论
共有 条评论