gpt4 book ai didi

c - ONVIF WS-Discover 1.0 - 客户端和事件处理程序

转载 作者:行者123 更新时间:2023-12-01 17:53:05 28 4
gpt4 key购买 nike

在我的 onvif 客户端应用程序中,我希望使用 gsoap 和 wsddapi.c 实现 WS-Discovery,但处理程序存在问题。我可以使用soap_wsdd_probe(wsddapi.c)通过UDP发送多播消息,我已经实现了soap_bind、listen和wsdd_event_probematches,但我没有收到来自服务的消息。

<小时/>
/*MY CLIENT*/

#include "wsdd.nsmap"
#include "soapH.h"
#include "wsddapi.h"

int main () {
struct soap* soap=soap_new();
struct soap* serv=soap_new(); //for the listner and the event handler
int time=100, port=53881;

if (!soap_valid_socket(soap_bind(soap, NULL, port, 100)))
{ soap_print_fault(soap, stderr);
exit(0);
}

soap->connect_flags=SO_BROADCAST;

const char * msg_uuid = NULL;
msg_uuid=soap_wsa_rand_uuid(soap);
soap_wsdd_Probe(soap, SOAP_WSDD_ADHOC, SOAP_WSDD_TO_TS,"soap.udp://239.255.255.250:3702",msg_uuid, NULL,"dp0:NetworkVideoTransmitter","", NULL);

soap_wsdd_listen(serv, 2); // listen for messages

soap_destroy(soap);
soap_end(soap);
soap_done(soap);
return 0;
}

wsddapi.c 中的事件处理程序我已经实现了 wsdd_event_probematches()

void wsdd_event_ProbeMatches(struct soap *soap, unsigned int InstanceId, const char *SequenceId, unsigned int MessageNumber, const char *MessageID, const char *RelatesTo, struct wsdd__ProbeMatchesType *matches){
printf("MessageID:%s",MessageID);
printf("%s",matches->ProbeMatch->XAddrs);
}

最佳答案

为了接收UDP,需要使用soap_new1(SOAP_IO_UDP)创建soap实例

gSOAP 的文档对于 WS-Discovery 插件相当晦涩,我对用于发送请求的肥皂实例和用于收集答案的肥皂实例感到困惑。
为了接收多播请求的单播答案,需要使用相同的肥皂实例:

int main(int argc, char** argv)
{
struct soap* serv = soap_new1(SOAP_IO_UDP);
if (!soap_valid_socket(soap_bind(serv, NULL, 0, 1000)))
{
soap_print_fault(serv, stderr);
exit(1);
}
int res = soap_wsdd_Probe(serv,
SOAP_WSDD_ADHOC,
SOAP_WSDD_TO_TS,
"soap.udp://239.255.255.250:3702",
soap_wsa_rand_uuid(serv),
NULL,
NULL,
NULL,
"");
if (res != SOAP_OK)
{
soap_print_fault(serv, stderr);
exit(1);
}
soap_wsdd_listen(serv, 1);
soap_destroy(serv);
soap_end(serv);
soap_done(serv);
return 0;
}

关于c - ONVIF WS-Discover 1.0 - 客户端和事件处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27061083/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com