win7下vs中实现onvif discovery(客户端、服务端)

本文介绍了如何在 Windows 7 上的 Visual Studio 中使用 gSOAP 库实现 ONVIF 设备的发现功能。通过提供服务端和客户端的代码示例,演示了如何编写 Probe、Hello 和 Bye 消息。服务端代码包括对这些消息的定义以及 main 函数的实现。客户端代码则需要生成相应代码。通过 ONVIF Device Test Tool 测试,服务端可以被成功发现。然而,要搜索特定设备,可能需要进一步修改 soap_call___dndl__Probe 函数及 printf 输出结构体的指针,同时考虑网络环境。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 完整代码:http://download.youkuaiyun.com/detail/shenhuaikun/5234203

github:完整代码

用gosap生成C代码框架在这里忽略。

1.服务端需要添加的代码:首先对Probe、Hello、Bye进行了定义,然后对编写main函数。

//#include <uuid/uuid.h> #include "soapH.h" #include "soapStub.h"

SOAP_FMAC5 int SOAP_FMAC6 __dndl__Probe(struct soap* soap, struct d__ProbeType *d__Probe, struct d__ProbeMatchesType *d__ProbeMatches) {  static struct d__ProbeMatchType ProbeMatch;  static struct d__ScopesType scopes;     static char MessageID[100];     static char szXAddr[64];     static char szEndpointReference[64];     static struct wsa__Relationship wsa_RelatesTo;

    unsigned char MacAddr[8] ={0x00, 0x16, 0xe8, 0x53, 0x13, 0xc7};     int localIP = inet_addr("192.168.7.33");  //0x6207A8C0     //localIP = niGetLocalIPAddr(g_netEthNi);     //memcpy(MacAddr, niGetHwAddr(g_netEthNi), 6);

    //    if(d__Probe->Types && strcasecmp(d__Probe->Types,"dn:NetworkVideoTransmitter")==0)

    sprintf(szXAddr, "http://%s/onvif/device_service", inet_ntoa(*((struct in_addr *)&localIP)));  sprintf(szEndpointReference, "urn:uuid:11229344-5566-7788-99aa-%02x%02x%02x%02x%02x%02x",                         MacAddr[0],MacAddr[1],MacAddr[2],MacAddr[3],MacAddr[4],MacAddr[5]);

 printf("__dndl__Probe %p, %p, %d\n", d__ProbeMatches, d__ProbeMatches->ProbeMatch, d__ProbeMatches->__sizeProbeMatch);  soap_default_d__ProbeMatchType(soap, &ProbeMatch);  soap_default_d__ScopesType(soap, &scopes);    if (soap->header)  {         //uuid_t uuid;            //uuid_generate(uuid);         strcpy(MessageID, "urn:uuid:");//urn:uuid:         //uuid_unparse(uuid, MessageID+9);

  if(soap->header->wsa__MessageID)   {    //printf("remote wsa__MessageID : %s\n",soap->header->wsa__MessageID);     soap->header->wsa__RelatesTo =&wsa_RelatesTo;    soap_default__wsa__RelatesTo(soap, soap->header->wsa__RelatesTo);    soap->header->wsa__RelatesTo->__item = soap->header->wsa__MessageID;

   soap->header->wsa__MessageID = MessageI

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值