Exemple #1
0
        /// <summary>
        /// Returns the message itself as a Byte array
        /// </summary>
        /// <returns>Byte array containing the message itself</returns>
        public byte[] ToByteArray()
        {
            byte[] programNameInBytes   = System.Text.Encoding.ASCII.GetBytes(ServerName);
            byte[] numberInBytes        = BitConverter.GetBytes(RandNumber);
            byte[] localIPInBytes       = ServerIPAddress.GetAddressBytes();
            byte[] listeningPortInBytes = BitConverter.GetBytes(ServerListeningPort);


            byte[] offerMessage    = new byte[programNameInBytes.Length + numberInBytes.Length + localIPInBytes.Length + listeningPortInBytes.Length];
            int    lastByteWritten = 0;

            for (int i = 0; i < programNameInBytes.Length; i++)
            {
                offerMessage[lastByteWritten] = programNameInBytes[i];
                lastByteWritten++;
            }
            for (int i = 0; i < numberInBytes.Length; i++)
            {
                offerMessage[lastByteWritten] = numberInBytes[i];
                lastByteWritten++;
            }
            for (int i = 0; i < localIPInBytes.Length; i++)
            {
                offerMessage[lastByteWritten] = localIPInBytes[i];
                lastByteWritten++;
            }
            for (int i = 0; i < listeningPortInBytes.Length; i++)
            {
                offerMessage[lastByteWritten] = listeningPortInBytes[i];
                lastByteWritten++;
            }

            return(offerMessage);
        }
Exemple #2
0
        /// <summary>
        /// Returns the hash code for this instance.
        /// </summary>
        /// <returns>The hash code for this instance.</returns>
        public override int GetHashCode()
        {
            if (_cachedHashCode < 1)
            {
                unchecked
                {
                    _cachedHashCode = (ClientIPAddress != null ? ClientIPAddress.GetHashCode() : 0);
                    _cachedHashCode = (_cachedHashCode * 397) ^ ClientPort.GetHashCode();
                    _cachedHashCode = (_cachedHashCode * 397) ^ (ServerIPAddress != null ? ServerIPAddress.GetHashCode() : 0);
                    _cachedHashCode = (_cachedHashCode * 397) ^ ServerPort.GetHashCode();
                }
            }

            return(_cachedHashCode);
        }