Loading [MathJax]/extensions/tex2jax.js
Cocos2d-x  4.0.0
Public Member Functions | List of all members
WebSocket::Delegate Class Referenceabstract

The delegate class is used to process websocket events. More...

Public Member Functions

virtual ~Delegate ()
 Destructor of Delegate.
 
virtual void onOpen (WebSocket *ws)=0
 This function to be called after the client connection complete a handshake with the remote server.
 
virtual void onMessage (WebSocket *ws, const Data &data)=0
 This function to be called when data has appeared from the server for the client connection.
 
virtual void onClose (WebSocket *ws)=0
 When the WebSocket object connected wants to close or the protocol won't get used at all and current _readyState is State::CLOSING,this function is to be called.
 
virtual void onError (WebSocket *ws, const ErrorCode &error)=0
 This function is to be called in the following cases:
 

Detailed Description

The delegate class is used to process websocket events.

The most member function are pure virtual functions,they should be implemented the in subclass. NA

Constructor & Destructor Documentation

virtual ~Delegate ( )
inlinevirtual

Destructor of Delegate.

Member Function Documentation

virtual void onOpen ( WebSocket ws)
pure virtual

This function to be called after the client connection complete a handshake with the remote server.

This means that the WebSocket connection is ready to send and receive data.

Parameters
wsThe WebSocket object connected
virtual void onMessage ( WebSocket ws,
const Data data 
)
pure virtual

This function to be called when data has appeared from the server for the client connection.

Parameters
wsThe WebSocket object connected.
dataData object for message.
virtual void onClose ( WebSocket ws)
pure virtual

When the WebSocket object connected wants to close or the protocol won't get used at all and current _readyState is State::CLOSING,this function is to be called.

Parameters
wsThe WebSocket object connected.
virtual void onError ( WebSocket ws,
const ErrorCode error 
)
pure virtual

This function is to be called in the following cases:

  1. client connection is failed.
  2. the request client connection has been unable to complete a handshake with the remote server.
  3. the protocol won't get used at all after this callback and current _readyState is State::CONNECTING.
  4. when a socket descriptor needs to be removed from an external polling array. in is again the struct libwebsocket_pollargs containing the fd member to be removed. If you are using the internal polling loop, you can just ignore it and current _readyState is State::CONNECTING.
Parameters
wsThe WebSocket object connected.
errorWebSocket::ErrorCode enum,would be ErrorCode::TIME_OUT or ErrorCode::CONNECTION_FAILURE.

The documentation for this class was generated from the following file: