コード例 #1
0
        // This is the main method that receives a command, handles it, and closes the connection.
        private void HandleHeader(IAsyncResult ar)
        {
            int read = 0;

            try
            {
                read = mClient.Client.EndReceive(ar);
                if (read > 0)
                {
                    AutomationTestMessageID messageID = (AutomationTestMessageID)BitConverter.ToInt16(mHeaderData, 0);
                    short version    = BitConverter.ToInt16(mHeaderData, 2);
                    int   dataLength = BitConverter.ToInt32(mHeaderData, 4);
                    HandleMessageID(messageID, dataLength);
                }
                else
                {
                    Log("Read 0 bytes.");
                }
            }
            catch
            {
                // ignore
            }

            // Close the connection
            mVMInstance.HandleConnectionDone();

            // Delete reference to parent object
            mVMInstance = null;
        }
コード例 #2
0
        private void ReceiveHeader()
        {
            try
            {
                mClient.Client.BeginReceive(mHeaderData, 0, mHeaderBufferSize, SocketFlags.None, HandleHeader, null);
            }
            catch (Exception ex)
            {
                Log("Error while reading data from client " + mVMInstance.VMName + ": " + ex);

                // Close the connection
                mVMInstance.HandleConnectionDone();
                mVMInstance = null;
            }
        }
コード例 #3
0
 internal ConnectionHandler(TcpClient client, VMInstance vmInstance)
 {
     mClient     = client;
     mVMInstance = vmInstance;
 }