コード例 #1
0
ファイル: Chat.cs プロジェクト: sA1mon/ChatApp
        internal void Connect(string name, string ip, string port)
        {
            try
            {
                Thread.Sleep(150);
                ChatClient = new ChatClient(new InstanceContext(new Callback()),
                                            new NetHttpBinding
                {
                    CloseTimeout   = new TimeSpan(1, 0, 0),
                    OpenTimeout    = new TimeSpan(1, 0, 0),
                    ReceiveTimeout = new TimeSpan(1, 0, 0),
                    SendTimeout    = new TimeSpan(1, 0, 0)
                },
                                            new EndpointAddress($"http://{ip}:{port}/"));

                Me = ChatClient.Add(name, GetDriveSerial(), _rsa.Key);
                if (Me == null)
                {
                    throw new NullReferenceException();
                }

                Text += $": {name}";
            }
            catch (EndpointNotFoundException)
            {
                MessageBox.Show("Wrong IP or Port", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("You've been banned from this server", "Oops", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                Close();
            }
        }