BVB Source Codes

CRYENGINE Show SimpleHttpServerWebsocketEchoListener.cpp Source code

Return Download CRYENGINE: download SimpleHttpServerWebsocketEchoListener.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include <CryNetwork/ISimpleHttpServer.h>
  5.  
  6. #include "SimpleHttpServer/SimpleHttpServerWebsocketEchoListener.h"
  7.  
  8. #if defined(HTTP_WEBSOCKETS)
  9.  
  10. CSimpleHttpServerWebsocketEchoListener CSimpleHttpServerWebsocketEchoListener::s_singleton;
  11.  
  12. CSimpleHttpServerWebsocketEchoListener& CSimpleHttpServerWebsocketEchoListener::GetSingleton()
  13. {
  14.         return s_singleton;
  15. }
  16.  
  17. void CSimpleHttpServerWebsocketEchoListener::OnUpgrade(int connectionID)
  18. {
  19.         CryLogAlways("CSimpleHttpServerWebsocketEchoListener::OnUpgrade: connection %d upgraded to websocket!", connectionID);
  20.  
  21.         SMessageData data;
  22.         data.m_eType = eMT_Text;
  23.         data.m_pBuffer = "Upgraded connection to Websocket.\n";
  24.         data.m_bufferSize = 35;
  25.  
  26.         gEnv->pNetwork->GetSimpleHttpServerSingleton()->SendWebsocketData(connectionID, data, false);
  27. };
  28.  
  29. void CSimpleHttpServerWebsocketEchoListener::OnReceive(int connectionID, SMessageData& data)
  30. {
  31.         // BEWARE! This is for test purposes only!
  32.         // Technically we shouldn't display data.m_pBuffer directly as a string. There is no guarantee that the buffer will contain a null terminator,
  33.         // even if the data.type is set to eMT_Text.
  34.         // For safety (for exactly this reason), our message handler always appends a null, but does not include in the length of the message.
  35.         // (data.m_pBuffer is actually data.m_bufferSize + 1 in length, with the last char set to null).
  36.         CryLogAlways("CSimpleHttpServerWebsocketEchoListener::OnReceive: connection %d, MessageType %d: \"%s\"", connectionID, data.m_eType, data.m_pBuffer);
  37.  
  38.         // ECHO
  39.         // Send the incoming data back to the client
  40.         gEnv->pNetwork->GetSimpleHttpServerSingleton()->SendWebsocketData(connectionID, data, false);
  41. }
  42.  
  43. void CSimpleHttpServerWebsocketEchoListener::OnClosed(int connectionID, bool bGraceful)
  44. {
  45.         CryLogAlways("CSimpleHttpServerWebsocketEchoListener::OnClosed: connection %d, graceful = %d", connectionID, bGraceful);
  46. }
  47.  
  48. #endif // HTTP_WEBSOCKETS
  49.  
downloadSimpleHttpServerWebsocketEchoListener.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top