| Profilo di DexterC# Network library proje...FotoBlogElenchi | Guida |
|
|
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
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
Message manager members:
See: Complete overview
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.
/// _____________________________________________________________ {
//!* 1). Begin reading messages.
_Server.MessageMngr.BeginReadMessage();
{
ZNC.Message m_Message = _Server.MessageMngr.ReadMessage();
{
//!* SYSTEM SPECIFIC-MESSAGE DATA TYPES:
//!* 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:
//! //!* 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:
//! }//!switch
}//!While
_Server.MessageMngr.EndReadMessage();
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
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.
// E.g. The simplest message type is TEXTDATA, the DATA object is actually just a string type, as shown below:
/// _____________________________________________________________ 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
* 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. CommentiPer 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 RiferimentiL'URL di riferimento per questo intervento è: http://dexterz.spaces.live.com/blog/cns!9E6C0341ABD0C595!249.trak Blog che fanno riferimento a questo intervento
|
|
|