예제 #1
0
        public void PrepareOutgoingData(SocketAsyncEventArgs e, DataHolder handledDataHolder, byte[] data)
        {
            try
            {
                Log.Info("start PrepareOutgoingData");
                DataHoldingUserToken theUserToken = (DataHoldingUserToken)e.UserToken;
                theDataHolder = theUserToken.theDataHolder;

                //Determine the length of all the data that we will send back.
                int lengthOfCurrentOutgoingMessage =  data.Length;

                //So, now we convert the length integer into a byte array.
                //Aren't byte arrays wonderful? Maybe you'll dream about byte arrays tonight!
                Byte[] arrayOfBytesInPrefix = BitConverter.GetBytes(lengthOfCurrentOutgoingMessage);

                //Create the byte array to send.
                theUserToken.dataToSend = new Byte[theUserToken.sendPrefixLength + lengthOfCurrentOutgoingMessage];

                //Now copy the 3 things to the theUserToken.dataToSend.
                Buffer.BlockCopy(arrayOfBytesInPrefix, 0, theUserToken.dataToSend, 0, theUserToken.sendPrefixLength);
                //The message that the client sent is already in a byte array, in DataHolder.
                Buffer.BlockCopy(data, 0, theUserToken.dataToSend, theUserToken.sendPrefixLength, data.Length);
                theUserToken.sendBytesRemainingCount = theUserToken.sendPrefixLength + lengthOfCurrentOutgoingMessage;
                Log.Info( "theUserToken.sendPrefixLength " + theUserToken.sendPrefixLength + " lengthOfCurrentOutgoingMessage:" + lengthOfCurrentOutgoingMessage);
                theUserToken.bytesSentAlreadyCount = 0;
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
예제 #2
0
파일: Mediator.cs 프로젝트: kcitwm/dova
 public void HandleData(DataHolder incomingDataHolder)
 {   
     if (Program.watchProgramFlow == true)   //for testing
     {
         receiveSendToken = (DataHoldingUserToken)this.saeaObject.UserToken;
         Program.testWriter.WriteLine("Mediator HandleData() " + receiveSendToken.TokenId);
     }
     theDataHolder = theIncomingDataPreparer.HandleReceivedData(incomingDataHolder, this.saeaObject);
 }
예제 #3
0
        internal DataHolder HandleReceivedData(DataHolder incomingDataHolder, SocketAsyncEventArgs theSaeaObject)
        {
            DataHoldingUserToken receiveToken = (DataHoldingUserToken)theSaeaObject.UserToken;

            theDataHolder           = incomingDataHolder;
            theDataHolder.sessionId = receiveToken.SessionId;
            theDataHolder.receivedTransMissionId = this.ReceivedTransMissionIdGetter();
            theDataHolder.remoteEndpoint         = this.GetRemoteEndpoint();
            if ((Program.watchData == true) & (Program.runLongTest == false))
            {
                this.AddDataHolder();
            }

            return(theDataHolder);
        }
예제 #4
0
        internal DataHolder HandleReceivedData(DataHolder incomingDataHolder, SocketAsyncEventArgs theSaeaObject)
        {
            var receiveToken = (DataHoldingUserToken)theSaeaObject.UserToken;
            if (Program.watchProgramFlow == true)   //for testing
            {
                Program.testWriter.Log("HandleReceivedData() " + receiveToken.TokenId);
            }
            _theDataHolder = incomingDataHolder;
            _theDataHolder.SessionId = receiveToken.SessionId;
            _theDataHolder.ReceivedTransMissionId = this.ReceivedTransMissionIdGetter();
            _theDataHolder.RemoteEndpoint = this.GetRemoteEndpoint();
            if ((Program.watchData == true) & (Program.runLongTest == false))
            {
                this.AddDataHolder();
            }

            return _theDataHolder;
        }
예제 #5
0
        internal void PrepareOutgoingData(SocketAsyncEventArgs e, DataHolder handledDataHolder)
        {
            DataHoldingUserToken theUserToken = (DataHoldingUserToken)e.UserToken;

            if (Program.watchProgramFlow == true)   //for testing
            {
                Program.testWriter.WriteLine("Mediator PrepareOutgoingData() " + theUserToken.TokenId);
            }

            theDataHolder = handledDataHolder;

            //In this example code, we will send back the receivedTransMissionId,
            // followed by the
            //message that the client sent to the server. And we must
            //prefix it with the length of the message. So we put 3
            //things into the array.
            // 1) prefix,
            // 2) receivedTransMissionId,
            // 3) the message that we received from the client, which
            // we stored in our DataHolder until we needed it.
            //That is our communication protocol. The client must know the protocol.

            //Convert the receivedTransMissionId to byte array.
            Byte[] idByteArray = BitConverter.GetBytes(theDataHolder.receivedTransMissionId);

            //Determine the length of all the data that we will send back.
            Int32 lengthOfCurrentOutgoingMessage = idByteArray.Length + theDataHolder.dataMessageReceived.Length;

            //So, now we convert the length integer into a byte array.
            //Aren't byte arrays wonderful? Maybe you'll dream about byte arrays tonight!
            Byte[] arrayOfBytesInPrefix = BitConverter.GetBytes(lengthOfCurrentOutgoingMessage);

            //Create the byte array to send.
            theUserToken.dataToSend = new Byte[theUserToken.sendPrefixLength + lengthOfCurrentOutgoingMessage];

            //Now copy the 3 things to the theUserToken.dataToSend.
            Buffer.BlockCopy(arrayOfBytesInPrefix, 0, theUserToken.dataToSend, 0, theUserToken.sendPrefixLength);
            Buffer.BlockCopy(idByteArray, 0, theUserToken.dataToSend, theUserToken.sendPrefixLength, idByteArray.Length);
            //The message that the client sent is already in a byte array, in DataHolder.
            Buffer.BlockCopy(theDataHolder.dataMessageReceived, 0, theUserToken.dataToSend, theUserToken.sendPrefixLength + idByteArray.Length, theDataHolder.dataMessageReceived.Length);

            theUserToken.sendBytesRemainingCount = theUserToken.sendPrefixLength + lengthOfCurrentOutgoingMessage;
            theUserToken.bytesSentAlreadyCount   = 0;
        }
예제 #6
0
        public void PrepareOutgoingData(SocketAsyncEventArgs e, DataHolder handledDataHolder)
        {
            DataHoldingUserToken theUserToken = (DataHoldingUserToken)e.UserToken;
            if (Program.watchProgramFlow == true)   //for testing
            {
                Program.testWriter.WriteLine("Mediator PrepareOutgoingData() " + theUserToken.TokenId);
            }
            
            theDataHolder = handledDataHolder;

            //In this example code, we will send back the receivedTransMissionId,
            // followed by the
            //message that the client sent to the server. And we must
            //prefix it with the length of the message. So we put 3 
            //things into the array.
            // 1) prefix,
            // 2) receivedTransMissionId,
            // 3) the message that we received from the client, which
            // we stored in our DataHolder until we needed it.
            //That is our communication protocol. The client must know the protocol.

            //Convert the receivedTransMissionId to byte array.
            Byte[] idByteArray = BitConverter.GetBytes(theDataHolder.receivedTransMissionId);

            //Determine the length of all the data that we will send back.
            Int32 lengthOfCurrentOutgoingMessage = idByteArray.Length + theDataHolder.dataMessageReceived.Length;

            //So, now we convert the length integer into a byte array.
            //Aren't byte arrays wonderful? Maybe you'll dream about byte arrays tonight!
            Byte[] arrayOfBytesInPrefix = BitConverter.GetBytes(lengthOfCurrentOutgoingMessage);
            
            //Create the byte array to send.
            theUserToken.dataToSend = new Byte[theUserToken.sendPrefixLength + lengthOfCurrentOutgoingMessage];
            
            //Now copy the 3 things to the theUserToken.dataToSend.
            Buffer.BlockCopy(arrayOfBytesInPrefix, 0, theUserToken.dataToSend, 0, theUserToken.sendPrefixLength);
            Buffer.BlockCopy(idByteArray, 0, theUserToken.dataToSend, theUserToken.sendPrefixLength, idByteArray.Length);
            //The message that the client sent is already in a byte array, in DataHolder.
            Buffer.BlockCopy(theDataHolder.dataMessageReceived, 0, theUserToken.dataToSend, theUserToken.sendPrefixLength + idByteArray.Length, theDataHolder.dataMessageReceived.Length);
            
            theUserToken.sendBytesRemainingCount = theUserToken.sendPrefixLength + lengthOfCurrentOutgoingMessage;
            theUserToken.bytesSentAlreadyCount = 0;
        }
예제 #7
0
파일: DataPreparer.cs 프로젝트: kcitwm/dova
 public DataPreparer(DataHolder incomingDataHolder)
 {
     theDataHolder = incomingDataHolder;
     theDataHolder.receivedTransMissionId = TransMissionIdGetter();
 }
예제 #8
0
 internal void CreateNewDataHolder()
 {
     theDataHolder = new DataHolder();
 }
예제 #9
0
 public DataPreparer(DataHolder incomingDataHolder)
 {
     theDataHolder = incomingDataHolder;
     theDataHolder.receivedTransMissionId = TransMissionIdGetter();
 }
예제 #10
0
 public void CreateNewDataHolder()
 {
     theDataHolder = new DataHolder();
 }
 internal void CreateNewDataHolder()
 {
     theDataHolder = new DataHolder();
 }
예제 #12
0
 internal void HandleData(DataHolder incomingDataHolder)
 {
     theDataHolder = theIncomingDataPreparer.HandleReceivedData(incomingDataHolder, this.saeaObject);
 }