Пример #1
0
        /// <summary>
        /// Creates a connection request message.
        /// </summary>
        /// <param name="RemoteIP">The IP of the peer that will receive this message.</param>
        /// <param name="MessageType">The type of the message to create.</param>
        /// <returns>The connection request message.</returns>
        public static string CreateConnectionRequestMessage(string RemoteIP, TypeOfConnectionRequestMessage MessageType)
        {
            string type = string.Empty;

            switch (MessageType)
            {
                case TypeOfConnectionRequestMessage.ConnectionRequest:
                    {
                        type = "CONNECT";
                        break;
                    }
                case TypeOfConnectionRequestMessage.ConnectionAccepted:
                    {
                        type = "CONNECT_OK";
                        break;
                    }
                case TypeOfConnectionRequestMessage.ConnectionRefused:
                    {
                        type = "CONNECT_NO";
                        break;
                    }
                default:
                    {
                        return null;
                    }
            }

            string mess =   Global.P2P_Protocol + "\n" +
                type + "\n" +
                "Local-IP: " + Global.MyIP + ":"  +Global.ListeningPort + "\n" +
                "Remote-IP: " + RemoteIP + "\n" +
                "User-Agent: " + Global.UserAgent;

            return mess;
        }
Пример #2
0
        /// <summary>
        /// Creates a connection request message.
        /// </summary>
        /// <param name="RemoteIP">The IP of the peer that will receive this message.</param>
        /// <param name="MessageType">The type of the message to create.</param>
        /// <returns>The connection request message.</returns>
        public static string CreateConnectionRequestMessage(string RemoteIP, TypeOfConnectionRequestMessage MessageType)
        {
            string type = string.Empty;

            switch (MessageType)
            {
            case TypeOfConnectionRequestMessage.ConnectionRequest:
            {
                type = "CONNECT";
                break;
            }

            case TypeOfConnectionRequestMessage.ConnectionAccepted:
            {
                type = "CONNECT_OK";
                break;
            }

            case TypeOfConnectionRequestMessage.ConnectionRefused:
            {
                type = "CONNECT_NO";
                break;
            }

            default:
            {
                return(null);
            }
            }

            string mess = Global.P2P_Protocol + "\n" +
                          type + "\n" +
                          "Local-IP: " + Global.MyIP + ":" + Global.ListeningPort + "\n" +
                          "Remote-IP: " + RemoteIP + "\n" +
                          "User-Agent: " + Global.UserAgent;

            return(mess);
        }