Profilo di DexterC# Network library proje...FotoBlogElenchi Strumenti Guida

Blog


07 settembre

What's inside the message?

 
 
Before I'll tackle how to grant access to a connecting client or denied the request, I will fast forward a little bit and
talk about how to read messages received by the server.
 
Since I want Z-Communicator optimized on the receiving part behind the scene, at the socket level where the actual
receiving of packets is happening, other than that, there is no need to implement events or delegates on using
Z-Communicator, everything happening at the socket level will be reported via messaging.
 
Like for instance, If the server receives an incomming connection, a connected client requesting to create/join/leave
a game session or client asking for a gracefull disconnection, etzetera... etzetera... I will received an informative
message data from the server message manager "_Server.MessageMngr", and take appropriate action for that
particular message.
 
Z-Communicator have it's own custom data message type format, than just throwing a raw bytes coming from socket,
the received bytes format should conform with the custom format the system have, if the received bytes format does
not conform in any of the available message format it will be discarded and record it to the logger manager, telling
me that an alien bytes format  is  trying to get into the system  Wink sort of data validation and for some
security purposes at the same time. my implementation assures the that if I got a message it's an informative one
and not a garbage data Tongue out.
 
 
Message manager members:
MessageMngr
 
 
To be able to read messages from the message manager,  a simple steps are need to be  implemented,
just create a network message processing routine/method,  which  will be call  from  the main program
on every game update cycle,  in reference from above image, this is how to implement it  in code:
 
1. Begin reading messages.
2. Loop while there is available message to read. 
3. Read the message.
5. Process message base on message type.
6. End reading messages.
 
 
 
/// _____________________________________________________________
/// <summary>
/// N E T W O R K   M E S S A G E    P R O C E S S I N G
/// </summary>
public voidl ProcessNetworkMessages()
{

 
     //!* 1). Begin reading messages.
     _Server.MessageMngr.BeginReadMessage();
 
 
         
     //!* 2). Keep reading all available message received.
     while(  _Server.MessageMngr.MessageIsAvailable()  )
     {
 
 
 
              //!* 3). Read the message
              ZNC.Message m_Message = _Server.MessageMngr.ReadMessage();
 
 
 
              //!* 4). Process message package DATA, base on message type.
              switch ( m_Message.MessageType )
             {
 
 
 
                   //!* SYSTEM SPECIFIC-MESSAGE DATA TYPES:
               
                //!* System data message type
               case ZNE.MessageType.SYSDATA:
                      //!
                      this.ProcessSysDataMessage( m_Message ); break;
 
                    
 
                   //!* GAME SPECIFIC- MESSAGE DATA TYPES:
 
               //!* Meta data message type
               case ZNE.MessageType.METADATA:
                      //!
                     this.ProcessMetaDataMessage( m_Message ); break;
 
               //!* Text data message type
               case ZNE.MessageType.TEXTDATA:
                      //!
                      this.ProcessTextDataMessage( m_Message ); break;
 
               //!* Object data message type
               case ZNE.MessageType.OBJDATA:
                      //!
                      this.ProcessObjDataMessage( m_Message ); break;
 
               //!* Raw bytes data message type
               case ZNE.MessageType.BYTESDATA:
                      //!
                      this.ProcessRawBytesDataMessage( m_Message ); break;
 
               //!* Voice data message type: ( under development )
               case ZNE.MessageType.VOICEDATA:
                      //!
                      this.ProcessVoiceDataMessage( m_Message ); break;
 
 
 
                  //!* FILE HANDLING SPECIFIC-MESSAGE DATA TYPES:
 
                  //!* File data transfer, message advisory.
               case ZNE.MessageType.FILEDATA:
                      //!
                      this.ProcessFileDataMessage( m_Message ); break;
 
                  //!* Download file from web, message advisory.
               case ZNE.MessageType.DOWNLOADDATA:
                      //!
                      this.ProcessDownloadDataMessage( m_Message ); break
 
               //!* Web data message advisory.
               case ZNE.MessageType.WEBDATA:
                      //!
                      this.ProcessWebDataMessage( m_Message ); break;
 
 
 
             }//!switch
 
 
      }//!While
 
 
 
     //!* 5). End  reading messages.
     _Server.MessageMngr.EndReadMessage();
 
 
}//!Method 
 
 
 
 
Surprised What! reading messages while there is available data to read, it will make some hickups to the game and block game
logic for some time within the while(  _Server.MessageMngr.MessageIsAvailable()  ), because overtime I'm
expecting data to arrive. Nah, that is not the expecting case, that's why there's a begin read message -
"_Server.MessageMngr.BeginReadMessage()" declaration before reading all available data, It will only read
data that has been qued up since the last call from BeginReadMessage and all other messages that has been
left or currrently just arriving(which is happening in the background) will be read to the next game update
cycle, hickups and procedure blocking only comes along, if you'll  be receiving thousands of message per
frame or game update which is irrational and it won't happen on a normal multiplayer games Wink.
 
 
 
So, What's inside  the message? image below shows the members of message class where I can cast the
package DATA base on message type.
 
MESSAGE
 
// E.g. The simplest message type is TEXTDATA, the DATA object is actually just a string type, as shown below:
 
/// _____________________________________________________________
/// <summary>
/// TEXT DATA  MESSAGE  PROCESSING
/// </summary>
public void ProcessTextDataMessage(  ZNC.Message message )
{
 
    //!* It's safe from here to cast the message DATA as string, since the message data type is already been knowned as TEXTDATA.
    //!
    string  m_TextMessage  =  ( string )message.DATA
 
 
    if(        message.Command == 10  )  // Say, 10 is my user-defined game command for my chat box message board.
    {
           _ChatMessageBoard.InsertMessage( message.SenderName,  m_TextMessage );
    }
    else if( message.Command == 11  )  // Say, 11 is my user-defined game command as a private message sent to me.
    {        
---------------------------------------------------------------------------------------------------------------------------------------------|
 
 
 
Well, I guess my next  post should be the following Nerd :
 
* Dealing with network system MessageType.SYSDATA, how to read ZNC.SystemData from message and what action should be taken.
 
* What is meta data  MessageType.METADATA,  sending meta data using   ZNC.MetaDataWriiter and readng  ZNC.MetaData from received mesage.
* What is text data    MessageType.TEXTDATA,   sending text data using    ZNC.TextDataWriter   and reading Text data from received message.
* What is raw bytes   MessageType.BYTESDATA, sending raw bytes using   ZNC.BytesDataWriter and reading Raw bytes data from received message.
* What is object data MessageType.OBJDATA,     sending object data using ZNC.ObjDataWriter     and reading  Object data from received message.
* What is file data     MessageType.FILEDATA,    sending file data using      ZNC.FileDataWriter    and reading ZNC.FileData from received message.
 
* How to download file fom web and reading  ZNC.DownloadData advisory from received message.
* How to send web request        and reading  ZNC.WebData advisory from received message.
 
 
 

Commenti

Attendere...
Il commento immesso è troppo lungo. Immetti un commento più breve.
Immissione non effettuata. Riprova.
Impossibile aggiungere il commento al momento. Riprova più tardi.
Per aggiungere un commento è necessaria l'autorizzazione di un genitore. Chiedi autorizzazione
I tuoi genitori hanno disattivato i commenti.
Impossibile eliminare il commento al momento. Riprova più tardi.
Hai raggiunto il numero massimo di commenti pubblicabili giornalmente. Riprova tra 24 ore.
Impossibile lasciare commenti. La funzionalità è stata disattivata perché i sistemi hanno rilevato una possibile attività di spamming dal tuo account. Se ritieni che il tuo account è stato disattivato per errore, contatta il supporto tecnico di Windows Live.
Esegui il seguente controllo di protezione per completare la pubblicazione del commento.
I caratteri digitati nel controllo di protezione devono corrispondere ai caratteri dell'immagine o della riproduzione audio.

Per aggiungere un commento, accedi con il tuo Windows Live ID (se utilizzi Hotmail, Messenger o Xbox LIVE possiedi già un Windows Live ID). Accedi


Non hai ancora un Windows Live ID? Registrati

Riferimenti

L'URL di riferimento per questo intervento è:
http://dexterz.spaces.live.com/blog/cns!9E6C0341ABD0C595!249.trak
Blog che fanno riferimento a questo intervento
  • Nessuno