WsSession

All the web socket application should be drive from WsSession base class. Following base class methods can be override in the  application class implementation .

        /// <summary>
        ///  This methold will be called when initializing thing this object.
        ///  If  any properties has to be set 
        ///  while initializing this object, override this method.
        /// </summary>
        protected virtual void OnInit()
        {
        }


        /// <summary>
        /// This methold will be  called 
        /// when incomming handshake message received and processed.
        /// You can get client information and cookies( if  there is any sent by client).
        /// You can also  validate the  user based on handskae information  
        /// base on client infromation and set  the new cookies 
        /// to the client in this point.
        /// </summary>
        protected virtual void OnHandshakeReceived()
        {
        }

        /// <summary>
        /// This methold will be called  when server 
        /// completed the server handshaker information
        /// and before sending it to client.
        /// We can set addtional server variables in this point
        /// </summary>
        protected virtual void OnHandShakeCompleting()
        {
        }

        /// <summary>
        /// This method will be called after  handshake completed () Server 
        /// sent the handshake header information to client).
        /// </summary>
        protected virtual void OnHandShakeCompleted()
        {
        }

        /// <summary>
        ///  This methold will be called when text message is received from client.
        ///  This method is used to process the partly text message
        /// </summary>
        protected virtual void OnTextMessageReceived(string message, bool bCompleted)
        {
        }

        /// <summary>
        /// This method is call to process the complete text message
        /// </summary>
        /// <param name="message"></param>
        protected virtual void OnTextMessageReceived(string message)
        {
        }

        /// <summary>
        /// Process the received Binarry message
        /// </summary>
        /// <param name="data"></param>
        /// <param name="bCompleted"></param>
        protected virtual void OnBinaryDataReceived(byte[] data, bool bCompleted)
        {
        }



        /// <summary>
        ///  This method will return the ping data to be sent.
        ///  The default ping sent the empty data.
        ///  If you want to customize the ping data to be sent, override this method 
        ///  and return the data to be sent.
        /// </summary>
        /// <returns>Ping data to be sent</returns>
        protected virtual byte[] OnPingSending()
        {
            return new byte[0];
        }

        /// <summary>
        ///  This method will return the pong data to be sent.
        ///  The default pong sent the empty data.
        ///  If you want to customize the pong data to be sent, override this method 
        ///  and return the data to be sent.
        /// </summary>
        /// <returns>Pong data to be sent</returns>
        protected virtual byte[] OnPongSending()
        {
            return new byte[0];
        }


        /// <summary>
        ///  This methold will be called when ping is receided from network
        ///  If you want to do any action based on the recceived ping data then, you should override this method.
        /// </summary>
        /// <param name="ping">Ping data received</param>
        protected virtual void OnPingReceived(byte[] pingData)
        {
        }

        /// <summary>
        ///  This method will be called when when pong data received from network.
        ///  If you want to do any action based on the recceived pong data then, you should override this method.
        /// </summary>
        /// <param name="pongData">Pong data received</param>
        protected virtual void OnPongReceived(byte[] pongData)
        {
        }


        /// <summary>
        ///  This method will be called when connection is closing by server or client
        /// </summary>
        protected virtual void OnClose()
        {
        }

        /// <summary>
        /// This method will called to pushing da data from server to client.
        /// </summary>
        protected virtual void OnPushData()
        {
        }

 

The WsSession class has following protected  variables :

 

        /// <summary>
        /// User friendly name of this sesssion. 
        /// They can set the name for this session in the sub class.
        /// it can use for idently the given session by name. 
        /// The default value is session id.
        /// </summary>
        protected string sessionName;

        /// <summary>
        /// Receiver object. 
        /// All the data will be receive by this object
        /// </summary>
        protected WsRequest receiver;


        /// <summary>
        ///  Sender Object. 
        ///  All the data will be send to the client using this object.
        /// </summary>
        protected WsResponse sender;

        /// <summary>
        /// Application object belong to this session
        /// </summary>
        protected IWsApplicationSessions application;

        /// <summary>
        /// All the client variables stored in this hash table
        /// </summary>
        protected Hashtable clientVariables ;

        /// <summary>
        /// All the server variables stored in this dictionary
        /// </summary>
        protected Dictionary<string, string> serverVariables;

 


WsResponse

The purpose of this class is to send the data to the client.  The instance of this class is available in the WsSession object as member variable.

      
        /// <summary>
        /// Set the deault Frame size
        /// </summary>
        /// <param name="defaultFrameSize"></param>
        public void SetDefaultFrameSize(long defaultFrameSize)

        /// <summary>
        /// Send the text data through the web socket
        /// </summary>
        /// <param name="data"></param>
        public void Send(string data)

        /// <summary>
        /// Send the data to all session objects in the application
        /// </summary>
        /// <param name="data"></param>
        public void Broadcast(string data)

        /// <summary>
        /// Send this data through the web socket
        /// </summary>
        /// <param name="data"></param>
        public void Send(byte[] data, Opcode opcode)

Last edited Jun 16, 2012 at 4:23 AM by chandru0507, version 9

Comments

No comments yet.