コード例 #1
0
ファイル: ClientForm.cs プロジェクト: ipenn/Networking.cs
        private void Connect()
        {
            if (client == null || !client.IsConnected)
            {
                string[] parts = txtHost.Text.Split(':');
                string   ip    = parts[0];
                ushort   port  = 5000;
                if (parts.Length == 2 && !string.IsNullOrEmpty(parts[1]) && ushort.TryParse(parts[1], out ushort tmpPort))
                {
                    port = tmpPort;
                }

                client?.Disconnect();
                client = new PlainClient(this)
                {
                    EnableLogging = true
                };
                client.OnConnected       += Client_OnConnectedChanged;
                client.OnDisconnected    += Client_OnConnectedChanged;
                client.OnMessageReceived += Client_OnMessageReceived;
                txtHost.Enabled           = false;
                host = $"{ip}:{port}";
                AddMessage("[CLIENT] Connecting to the Server @ " + host + "...");
                rtbMessages.Show();
                ChangeStatus("Connecting to " + host + "...");
                client.Connect(ip, port);
            }
        }
コード例 #2
0
ファイル: ClientForm.cs プロジェクト: ipenn/Networking.cs
        private void ClientForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            Settings.Default.LastNick = txtNick.Text;
            Settings.Default.LastHost = txtHost.Text;
            Settings.Default.Save();
            AddMessage("[CLIENT] Settings saved");

            try
            {
                if (client != null && client.IsConnected)
                {
                    client.Disconnect();
                }
            }
            catch { }
        }