我把发现摄像头的详细代码贴上来:
#include "soapH.h" #include "wsdd.nsmap" #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <sys/types.h> #include <uuid/uuid.h> #include <netinet/in.h> #define set_block_fd(fd) fcntl(fd, F_SETFL, 0) #define set_nonblock_fd(fd) fcntl(fd, F_SETFL, NOBLOCK) #define SMALL_INFO_LENGTH 20 #define IP_LENGTH 20 #define INFO_LENGTH 100 int main(int argc, char **argv) { //discovery devices struct soap *soap; struct wsdd__ProbeType req; //用于发送消息描述 /*struct wsdd__ProbeType { char *Types; optional element of type xsd:QName struct wsdd__ScopesType *Scopes; optional element of type wsdd:ScopesType };*/ struct __wsdd__ProbeMatches resp;//请求消息的回应 /* struct __wsdd__ProbeMatches { struct wsdd__ProbeMatchesType *wsdd__ProbeMatches; optional element of type wsdd:ProbeMatchesType }; struct wsdd__ProbeMatchesType { int __sizeProbeMatch; // SOAP 1.2 RPC return element (when namespace qualified) sequence of elements <ProbeMatch> struct wsdd__ProbeMatchType *ProbeMatch; // optional element of type wsdd:ProbeMatchType }; struct wsdd__ProbeMatchType { struct wsa__EndpointReferenceType wsa__EndpointReference; required element of type wsa:EndpointReference char *Types; optional element of type xsd:QName struct wsdd__ScopesType *Scopes; optional element of type wsdd:ScopesType char *XAddrs; optional element of type wsdd:UriListType unsigned int MetadataVersion; required element of type xsd:unsignedInt }; struct wsa__EndpointReferenceType { char *Address; required element of type xsd:string struct wsa__ReferencePropertiesType *ReferenceProperties; optional element of type wsa:ReferencePropertiesType struct wsa__ReferenceParametersType *ReferenceParameters; optional element of type wsa:ReferenceParametersType char **PortType; optional element of type xsd:QName struct wsa__ServiceNameType *ServiceName; optional element of type wsa:ServiceNameType int __size; sequence of elements <-any> char **__any; char *__anyAttribute; optional attribute of type xsd:anyType }; */ /* struct wsdd__ScopesType { char *__item; char *MatchBy; // optional attribute of type xsd:string };*/ struct wsdd__ScopesType sScope;//描述查找哪类的Web服务 struct SOAP_ENV__Header header;//soap消息头描述 /* //SOAP Header: struct SOAP_ENV__Header { char *wsa__MessageID; //optional element of type wsa:MessageID struct wsa__Relationship *wsa__RelatesTo; //optional element of type wsa:RelatesTo struct wsa__EndpointReferenceType *wsa__From; //optional element of type wsa:From struct wsa__EndpointReferenceType *wsa__ReplyTo; // mustUnderstand struct wsa__EndpointReferenceType *wsa__FaultTo; //mustUnderstand char *wsa__To; //mustUnderstand char *wsa__Action; //mustUnderstand struct wsdd__AppSequenceType *wsdd__AppSequence; //optional element of type wsdd:AppSequenceType };*/ int count = 0; int result = 0; uuid_t uuid; uuid_generate(uuid); soap = soap_new(); if(soap == NULL) { printf("soap error!\n"); return -1; } //soap_set_namespaces(struct soap *soap, const struct Namespace *p); soap_set_namespaces(soap, namespaces); //soap->recv_timeout = 5; //超过5秒钟没有数据就退出 soap_default_SOAP_ENV__Header(soap, &header); /* SOAP_FMAC3 void SOAP_FMAC4 soap_default_SOAP_ENV__Header(struct soap *soap, struct SOAP_ENV__Header *a) { (void)soap; (void)a; // appease -Wall -Werror soap_default__wsa__MessageID(soap, &a->wsa__MessageID); a->wsa__RelatesTo = NULL; a->wsa__From = NULL; a->wsa__ReplyTo = NULL; a->wsa__FaultTo = NULL; soap_default__wsa__To(soap, &a->wsa__To); soap_default__wsa__Action(soap, &a->wsa__Action); a->wsdd__AppSequence = NULL; }*/ header.wsa__MessageID = uuid; header.wsa__To= "urn:schemas-xmlsoap-org:ws:2005:04:discovery"; header.wsa__Action= "http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe"; soap->header = &header; soap_default_wsdd__ScopesType(soap, &sScope); sScope.__item = ""; soap_default_wsdd__ProbeType(soap, &req); req.Scopes = &sScope; req.Types = ""; result = soap_send___wsdd__Probe(soap, "soap.udp://239.255.255.250:3702", NULL, &req); do { result = soap_recv___wsdd__ProbeMatches(soap, &resp); if(soap -> error) { printf("soap error!\n"); break; } else{ //print IPC's information printf("===========================================\n"); printf("sizeProbeMatch:%d\n",resp.wsdd__ProbeMatches->__sizeProbeMatch); printf("MetadataVersion:%d\n",resp.wsdd__ProbeMatches->ProbeMatch->MetadataVersion); printf("item:%s\n",resp.wsdd__ProbeMatches->ProbeMatch->Scopes->__item); printf("QName:%s\n",resp.wsdd__ProbeMatches->ProbeMatch->Types); printf("xsd:string:%s\n",resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.Address); printf("xsd:QName:%p\n",resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.PortType); printf("wsa:ServiceNameType:%p\n",resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.ServiceName); printf("sequence of elements:%d\n",resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__size); printf("xsd:anyType:%s\n",resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__anyAttribute); printf("endpoint any:%p\n",resp.wsdd__ProbeMatches->ProbeMatch->wsa__EndpointReference.__any); printf("wsdd:UriListType:%s\n",resp.wsdd__ProbeMatches->ProbeMatch->XAddrs); printf("===========================================\n"); } }while(1); soap_destroy(soap); soap_end(soap); soap_done(soap); return result; }