⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 client-tutorial.html

📁 另一 UPNP SDK 支持在UNIX/LINUX上运行。 UPnP是一种网络协议
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Writing a UPnP Client</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="GUPnP Reference Manual"><link rel="up" href="tutorial.html" title="Part聽I.聽Tutorial"><link rel="prev" href="overview.html" title="Overview"><link rel="next" href="server-tutorial.html" title="Writing a UPnP Service"><meta name="generator" content="GTK-Doc V1.10 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="part" href="tutorial.html" title="Part聽I.聽Tutorial"><link rel="chapter" href="overview.html" title="Overview"><link rel="chapter" href="client-tutorial.html" title="Writing a UPnP Client"><link rel="chapter" href="server-tutorial.html" title="Writing a UPnP Service"><link rel="part" href="api.html" title="Part聽II.聽Reference"><link rel="chapter" href="api-device-info.html" title="Device Information"><link rel="chapter" href="api-device-control.html" title="Device Control"><link rel="chapter" href="api-device-impl.html" title="Device Implementation"><link rel="chapter" href="api-utility.html" title="Utility Functions"><link rel="chapter" href="api-tools.html" title="Tools"><link rel="part" href="schemas.html" title="Part聽III.聽XML Schemas"><link rel="chapter" href="schemas-device.html" title="Device Description"><link rel="chapter" href="schemas-service.html" title="Service Description"><link rel="glossary" href="glossary.html" title="Glossary"><link rel="index" href="ix01.html" title="Index"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="overview.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="tutorial.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GUPnP Reference Manual</th><td><a accesskey="n" href="server-tutorial.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr></table><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="client-tutorial"></a>Writing a UPnP Client</h2></div></div></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2552387"></a>Introduction</h2></div></div></div><p>      This chapter explains how to write an application which fetches the      external IP address from an UPnP-compliant modem.  To do this a      <em class="glossterm">Control Point</em> is created, which searches for      services of the type      <code class="literal">urn:schemas-upnp-org:service:WANIPConnection:1</code> (part of      the <a class="ulink" href="http://upnp.org/standardizeddcps/igd.asp" target="_top">Internet Gateway      Device</a> specification).  As services are discovered      <em class="firstterm">Service Proxy</em> objects are created by GUPnP to allow      interaction with the service, on which we can invoke the action      <code class="function">GetExternalIPAddress</code> to fetch the external IP      address.    </p></div><div class="simplesect" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2623978"></a>Finding Services</h2></div></div></div><p>      First, we initialize GUPnP and create a control point targeting the      service type.  Then we connect a signal handler so that we are notified      when services we are interested in are found.    </p><pre class="programlisting">#include &lt;libgupnp/gupnp-control-point.h&gt;static GMainLoop *main_loop;intmain (int argc, char **argv){  GUPnPContext *context;  GUPnPControlPoint *cp;    /* Required initialisation */  g_thread_init (NULL);  g_type_init ();  /* Create a new GUPnP Context.  By here we are using the default GLib main     context, and connecting to the current machine's default IP on an     automatically generated port. */  context = gupnp_context_new (NULL, NULL, 0, NULL);  /* Create a Control Point targeting WAN IP Connection services */  cp = gupnp_control_point_new    (context, "urn:schemas-upnp-org:service:WANIPConnection:1");  /* The service-proxy-available signal is emitted when any services which match     our target are found, so connect to it */  g_signal_connect (cp,		    "service-proxy-available",		    G_CALLBACK (service_proxy_available_cb),		    NULL);  /* Tell the Control Point to start searching */  gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp), TRUE);    /* Enter the main loop. This will start the search and result in callbacks to     service_proxy_available_cb. */  main_loop = g_main_loop_new (NULL, FALSE);  g_main_loop_run (main_loop);  /* Clean up */  g_main_loop_unref (main_loop);  g_object_unref (cp);  g_object_unref (context);    return 0;}static voidservice_proxy_available_cb (GUPnPControlPoint *cp,                            GUPnPServiceProxy *proxy){  /* 鈥

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -