当前位置: 首页>>代码示例>>C++>>正文


C++ NPT_DataBuffer::SetBuffer方法代码示例

本文整理汇总了C++中NPT_DataBuffer::SetBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ NPT_DataBuffer::SetBuffer方法的具体用法?C++ NPT_DataBuffer::SetBuffer怎么用?C++ NPT_DataBuffer::SetBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NPT_DataBuffer的用法示例。


在下文中一共展示了NPT_DataBuffer::SetBuffer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: listen

void Server::listen()
{
    _aliveThread = new std::thread([] () {
        int delay = 10000;

        while (true)
        {
            sleep(delay);
            printf("SENDING ALIVE\n");
            sendAlive();

            delay = (delay == 10000 ? 20000 : 180000);
        }
    });

    _listenerThread = new std::thread([] () {
        bool bindErrorReported = false;

        while (true)
        {
            NPT_UdpMulticastSocket socket;
            NPT_IpAddress upnpAddress = getUPNPAddress();

            // TODO: Setup local port and network interface
            socket.SetTimeToLive(4);
            socket.JoinGroup(upnpAddress);

            while (true)
            {
                char* buf = new char[1024];

                NPT_DataBuffer receivePacket;
                NPT_SocketAddress address;
                receivePacket.SetBuffer((NPT_Byte*)buf, 1024);

                socket.Receive(receivePacket, &address);

                std::string s((char*)receivePacket.GetData(), receivePacket.GetDataSize());
                if (s.compare(0, 8, "M-SEARCH") == 0)
                {
                    NPT_String remoteAddr = address.GetIpAddress().ToString();
                    int remotePort = address.GetPort();

                    // if (gMS->isAddressAllowed(address))
                    {
                        if (s.find_first_of("urn:schemas-upnp-org:service:ContentDirectory:1") > 0)
                        {
                            sendDiscover(remoteAddr.GetChars(), remotePort, "urn:schemas-upnp-org:service:ContentDirectory:1");
                        }

                        if (s.find_first_of("upnp:rootdevice") > 0)
                        {
							sendDiscover(remoteAddr.GetChars(), remotePort, "upnp:rootdevice");
						}

                        if (s.find_first_of("urn:schemas-upnp-org:device:MediaServer:1") > 0)
                        {
							sendDiscover(remoteAddr.GetChars(), remotePort, "urn:schemas-upnp-org:device:MediaServer:1");
						}

						if (s.find_first_of("ssdp:all") > 0)
                        {
							sendDiscover(remoteAddr.GetChars(), remotePort, "urn:schemas-upnp-org:device:MediaServer:1");
						}

						if (s.find_first_of(gMS->udnString()) > 0)
                        {
							sendDiscover(remoteAddr.GetChars(), remotePort, gMS->udnString());
						}
                    }
                }
                else if (s.compare(0, 6, "NOTIFY") == 0)
                {
                    /*
                    String remoteAddr = address.getHostAddress();
					int remotePort = receivePacket.getPort();

					logger.trace("Receiving a NOTIFY from [" + remoteAddr + ":" + remotePort + "]");
                    */
                }
            }
        }
    });
}
开发者ID:gpascualg,项目名称:MediaServer-,代码行数:84,代码来源:upnp.cpp


注:本文中的NPT_DataBuffer::SetBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。