upnp协议demo

来源:互联网 发布:matlab 数组转元胞 编辑:程序博客网 时间:2024/04/30 23:26

一、编译失败问题:

gcc  -Wall -O2 upnp_tv_device.o  sample_util.o -lpthread  ../../bin/libupnp.so -o  upnp_tv_device 

../../bin/libupnp.so: undefined reference to `__cxa_free_exception'
../../bin/libupnp.so: undefined reference to `operator new[](unsigned int)'
../../bin/libupnp.so: undefined reference to `__cxa_begin_catch'
../../bin/libupnp.so: undefined reference to `operator delete[](void*)'
../../bin/libupnp.so: undefined reference to `operator delete(void*)'
../../bin/libupnp.so: undefined reference to `__cxa_pure_virtual'
../../bin/libupnp.so: undefined reference to `__cxa_allocate_exception'
../../bin/libupnp.so: undefined reference to `__gxx_personality_v0'
../../bin/libupnp.so: undefined reference to `__cxa_throw'
../../bin/libupnp.so: undefined reference to `std::ios_base::Init::~Init()'
../../bin/libupnp.so: undefined reference to `__cxa_end_catch'
../../bin/libupnp.so: undefined reference to `typeinfo for int'
../../bin/libupnp.so: undefined reference to `vtable for __cxxabiv1::__class_type_info'
../../bin/libupnp.so: undefined reference to `std::ios_base::Init::Init()'
../../bin/libupnp.so: undefined reference to `__cxa_rethrow'
../../bin/libupnp.so: undefined reference to `operator new(unsigned int)'
../../bin/libupnp.so: undefined reference to `vtable for __cxxabiv1::__si_class_type_info'

../../bin/libupnp.so: undefined reference to `std::terminate()'


解决:

g++  -Wall -O2 upnp_tv_device.o  sample_util.o -lpthread  ../../bin/libupnp.so -o  upnp_tv_device 

应该链接了c++库,需要g++链接。


二、运行demo

[hatred@localhost tvdevice]$ ./upnp_tv_device 192.168.3.28 5431 tvdevicedesc.xml ./web
Intializing UPnP 
        with desc_doc_url=http://192.168.3.28:5431/tvdevicedesc.xml
                     ipaddress=192.168.3.28 port=5431
             web_dir_path=./web
UPnP Initialized
Specifying the webserver root directory -- ./web
Registering the RootDevice
RootDevice Registered
Initializing State Table
Found service: urn:schemas-upnp-org:service:tvcontrol:1
Found service: urn:schemas-upnp-org:service:tvpicture:1
State Table Initialized
Advertisements Sent
>> grewg
   Unknown command: grewg
   Valid Commands:
     Exit
>> 
   Unknown command:  
   Valid Commands:
     Exit


三、编译upnp_tv_ctrlpt 出错

[redsir@localhost tvdevice]$ make
gcc -Wall -O2 -I../../inc  -I ../../inc/tools -c upnp_tv_ctrlpt.c
In file included from upnp_tv_ctrlpt.c:37:
upnp_tv_ctrlpt.h:78: 错误:数组元素的类型不完全
upnp_tv_ctrlpt.c: In function ‘TvCtrlPointSendAction’:
upnp_tv_ctrlpt.c:443: 警告:未使用的变量 ‘tmpstr’
upnp_tv_ctrlpt.c:442: 警告:未使用的变量 ‘ActionXml’
make: *** [upnp_tv_ctrlpt.o] 错误 1

解决:

[fdsf@localhost tvdevice]$ vim upnp_tv_ctrlpt.h

+74 extern char *TvVarName[TV_SERVICE_SERVCOUNT][TV_MAXVARS];

[redsir@localhost tvdevice]$ g++  -Wall -O2 upnp_tv_ctrlpt.o sample_util.o  -lpthread  ../../bin/libupnp.so -o  upnp_tv_ctrlpt 


四、控制端运行

启动upnp服务:

[root@localhost tvdevice]# ./upnp_tv_device 192.168.1.228 5231 tvdevicedesc.xml ./web

启动upnp监测:

# ./upnp_tv_ctrlpt 192.168.1.4 5232

下面监测到了PPTV的DLNA多屏推送服务。

======================================================================
----------------------------------------------------------------------
UPNP_DISCOVERY_ADVERTISEMENT_ALIVE
ErrCode     =  0
Expires     =  1800
DeviceId    =  uuid:Upnp-TVEmulator-1_0-1234567890001
DeviceType  =  
ServiceType =  urn:schemas-upnp-org:service:tvpicture:1
ServiceVer  =  08</UDN>
    <presentationURL>http://www.pptv.com/</presentationURL>
    <dlna:X_DLNADOC xmlns:dlna="urn:schemas-dlna-org:device-1
Location    =  http://192.168.1.228:5231/tvdevicedesc.xml
OS          =   Linux/2.6.18-238.el5 UPnP/1.0 Intel UPnP SDK/1.0
Ext         =  
----------------------------------------------------------------------
======================================================================


下面是本地

Error obtaining device description from http://192.168.1.228:5231/tvdevicedesc.xml -- error = -204

TvCtrlPointPrintList:

Error obtaining device description from http://192.168.1.228:5231/tvdevicedesc.xml -- error = -204

TvCtrlPointPrintList:

Error obtaining device description from http://192.168.1.228:5231/tvdevicedesc.xml -- error = -204



0 0