简体   繁体   English

使用Poco库的C ++ / IOS Websocket

[英]C++/IOS Websockets using the Poco Library

I've recently started using the Poco library (which I think is great) and I'm trying to create an Server to connect too using an ios application using socket.io - websocket's. 我最近开始使用Poco库(我认为很棒),并且我正在尝试创建一个服务器,该服务器也可以通过使用socket.io-websocket的ios应用程序进行连接。 I've managed to use an node js implementation to connect but require a C++ implementation. 我设法使用节点js实现进行连接,但是需要C ++实现。 I've stated by instantiating the websocket within the handleRequest method but unsure to what the next steps are... 我通过在handleRequest方法中实例化websocket进行了声明,但不确定下一步是什么...

Any help would be very much appreciated.. 任何帮助将不胜感激。

virtual void handleRequest(HTTPServerRequest &req, HTTPServerResponse &resp)
{
   char buffer[16384];

   WebSocket* ws = new WebSocket(req, resp);
   //ws->setKeepAlive(false);
   int flags;
   if (!ws->poll(500,Poco::Net::Socket::SELECT_READ || Poco::Net::Socket::SELECT_ERROR))
   {   
      cout << ".";
   }   
   else
   {   
       int n = ws->receiveFrame(buffer, sizeof(buffer), flags);
       if (n > 0)
       {   
           if ((flags & WebSocket::FRAME_OP_BITMASK) == WebSocket::FRAME_OP_BINARY)
           {   
               // process and send out to all other clients
           }   
       }   
   }   

}

Next steps depend on what you are trying to do. 下一步取决于您要执行的操作。 Once connected, you have an open channel that you can use for two-way data exchange between browser and server. 连接后,您将拥有一个开放通道,可用于浏览器和服务器之间的双向数据交换。

For details, see the WebSocketServer example . 有关详细信息,请参见WebSocketServer示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM