示例#1
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();
            this.AddDataHolder();
            return(theDataHolder);
        }
示例#2
0
        internal void PrepareOutgoingData(SocketAsyncEventArgs e,
                                          DataHolder handledDataHolder)
        {
            DataHoldingUserToken theUserToken = (DataHoldingUserToken)e.UserToken;

            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 in to 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 protocal. The client must know the protocal.

            // 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.
            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;
        }
示例#3
0
文件: Mediator.cs 项目: husm/socket
 internal void HandleData(DataHolder incomingDataHolder)
 {
     theDataHolder = theIncomingDataPreparer.HandleReceivedData(incomingDataHolder, this.saeaObject);
 }
示例#4
0
 internal void CreateNewDataHolder()
 {
     theDataHolder = new DataHolder();
 }