Exemple #1
0
        /// <summary>
        /// </summary>
        /// <param name="address">
        /// </param>
        /// <param name="port">
        /// </param>
        /// <param name="received">
        /// </param>
        public static void StartClient(IPAddress address, int port, OnReceivedMessageFromServer received)
        {
            if (isServer == true)
            {
                LogUtil.Debug(DebugInfoDetail.Error, "ZoneCom already initialized as Server.");
                return;
            }

            if (isServer == false)
            {
                LogUtil.Debug(DebugInfoDetail.Error, "ZoneCom already initialized as Client.");
                return;
            }

            if (received != null)
            {
                ReceivedMessageFromServer += received;
                serverIP   = address;
                serverPort = port;
            }

            client                  = new ZoneComClient();
            client.OnConnect       += ClientToServerConnected;
            client.OnDisconnect    += ClientToServerDisconnected;
            client.MessageReceived += ClientMessageReceived;
            try
            {
                client.ConnectToServer(address, port);
            }
            catch (Exception)
            {
                ClientToServerDisconnected(null, EventArgs.Empty);
                return;
            }

            isServer = false;
        }
        /// <summary>
        /// </summary>
        /// <param name="address">
        /// </param>
        /// <param name="port">
        /// </param>
        /// <param name="received">
        /// </param>
        public static void StartClient(IPAddress address, int port, OnReceivedMessageFromServer received)
        {
            if (isServer == true)
            {
                LogUtil.Debug("ZoneCom already initialized as Server.");
                return;
            }

            if (isServer == false)
            {
                LogUtil.Debug("ZoneCom already initialized as Client.");
                return;
            }

            if (received != null)
            {
                ReceivedMessageFromServer += received;
                serverIP = address;
                serverPort = port;
            }

            client = new ZoneComClient();
            client.OnConnect += ClientToServerConnected;
            client.OnDisconnect += ClientToServerDisconnected;
            client.MessageReceived += client_MessageReceived;
            try
            {
                client.ConnectToServer(address, port);
            }
            catch (Exception)
            {
                ClientToServerDisconnected();
                return;
            }

            isServer = false;
        }