upnpx学习笔记

开源代码:http://code.google.com/p/upnpx/

 upnpx是一个支持dlna协议的局域网多媒体共享与播放控制的第三方框架。

http://upnp.org/sdcps-and-certification/resources/sdks/

Good UPnP documentation is available at at the website http://upnp.org. The architecture is described in the following document UPNP Device Architecture Document

A UPnP session exist of several steps:

  • 0. Addressing
  • 1. Discovery
  • 2. Description
  • 3. Control
  • 4. Eventing
  • 5. Presentation

upnpx is an implementation of the UPnP Specifications and has API functions for the different steps. This tutorial give simple examples how to use the upnpx API in order to build your own UPnP Control Point.

This tutorial handles the 6 individual steps and starts at Step 0. Addressing.

0. Addressing

{UPnP specifications: "Through addressing, devices and control points get a network address".}

Basically this means that your device has to get an IP address. Since the OS handles this task we are lucky and don't have to do much. Just be sure you actually are connected to the network and have an IP address before using upnpx.

Next Step 1. Discovery

1. Discovery

{UPnP specifications: "Through discovery, control points find interesting device(s)."}

During Discovery we will search for any UPnP device on the local network. upnpx implements the SSDP protocol (Simple Service Discovery Protocol) and maintains an in-memory database of all devices on the network, it will automatically update this database when new devices are added or removed. Your code can read the database and get notifications when an update is done.

Check the project ./upnpx/projects/xcode3/upnpxdemo/upnpxdemo.xcodeproj to see an example of a functional ssdp implementation:

Basically, there are 3 steps to complete to implement SSDP:


1. Implement the Interface UPnPDBObserver:

RootViewController.h:

#import "UPnPDB.h"

@interface RootViewController : UITableViewController <UPnPDBObserver>{
  
        NSArray *mDevices; //BasicUPnPDevice*
}


//protocol UPnPDBObserver
-(void)UPnPDBWillUpdate:(UPnPDB*)sender;
-(void)UPnPDBUpdated:(UPnPDB*)sender;


2. Get a pointer to the discovery database via the UPnPManager, register yourself as an observer and tell the SSDP implementation to search for devices by calling searchSSDP:

RootViewController.m:

- (void)viewDidLoad {
  
    [super viewDidLoad];

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;

    UPnPDB* db = [[UPnPManager GetInstance] DB];
    
    mDevices = [db rootDevices]; //BasicUPnPDevice
    [mDevices retain];

    [db addObserver:(UPnPDBObserver*)self];
    
    //Optional; set User Agent
    [[[UPnPManager GetInstance] SSDP] setUserAgentProduct:@"upnpxdemo/1.0" andOS:@"OSX"];
    
    //Search for UPnP Devices 
    [[[UPnPManager GetInstance] SSDP] searchSSDP];      
    
    self.title = @"upnpx demo";
}


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值