public void TestUserExitCommand()
        {
            IPAddress ipaddress = IPAddress.Parse("127.0.0.1");
            Command   command   = new Command(CommandType.UserExit, ipaddress, null);

            System.IO.Stream fakeStream     = mocks.DynamicMock <System.IO.Stream>();
            byte[]           commandBytes   = { 0, 0, 0, 0 };
            byte[]           ipLength       = { 9, 0, 0, 0 };
            byte[]           ip             = { 49, 50, 55, 46, 48, 46, 48, 46, 49 };
            byte[]           metaDataLength = { 2, 0, 0, 0 };
            byte[]           metaData       = { 10, 0 };

            using (mocks.Ordered())
            {
                fakeStream.Write(commandBytes, 0, 4);
                fakeStream.Flush();
                fakeStream.Write(ipLength, 0, 4);
                fakeStream.Flush();
                fakeStream.Write(ip, 0, 9);
                fakeStream.Flush();
                fakeStream.Write(metaDataLength, 0, 4);
                fakeStream.Flush();
                fakeStream.Write(metaData, 0, 2);
                fakeStream.Flush();
            }
            mocks.ReplayAll();
            CMDClient client = new CMDClient(null, "Bogus network name");

            // we need to set the private variable here

            client.SendCommandToServerUnthreaded(command);
            mocks.VerifyAll();
        }
Пример #2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (this.btnLogin.Text == "Login")
            {
                frmLogin dlg = new frmLogin();
                dlg.ShowDialog();
                this.client = dlg.Client;

                if (this.client.Connected)
                {
                    this.client.CommandReceived += new CommandReceivedEventHandler(client_CommandReceived);
                    this.client.SendCommand(new Command(CommandType.FreeCommand, IPAddress.Broadcast, this.client.IP + ":" + this.client.NetworkName));
                    this.client.SendCommand(new Command(CommandType.SendClientList, this.client.ServerIP));
                    this.AddToList(this.client.IP.ToString(), this.client.NetworkName);
                    this.btnLogin.Text = "Log Off";
                }
            }
            else
            {
                this.btnLogin.Text = "Login";
                this.privateWindowsList.Clear();
                this.client.Disconnect();
                this.lstViwUsers.Items.Clear();
                this.txtNewMessage.Clear();
                this.txtNewMessage.Focus();
            }
        }
Пример #3
0
 public frmPrivate(CMDClient cmdClient, IPAddress friendIP, string name)
 {
     InitializeComponent();
     remoteClient                  = cmdClient;
     targetIP                      = friendIP;
     remoteName                    = name;
     lblPrivateChatName.Text       = name;
     remoteClient.CommandReceived += new CommandReceivedEventHandler(private_CommandReceived);
 }
Пример #4
0
 public frmPrivate(CMDClient cmdClient, IPAddress friendIP, string name)
 {
     InitializeComponent();
     this.remoteClient = cmdClient;
     this.targetIP     = friendIP;
     this.remoteName   = name;
     this.Text        += " With " + name;
     this.remoteClient.CommandReceived += new CommandReceivedEventHandler(private_CommandReceived);
 }
Пример #5
0
 public frmPrivate(CMDClient cmdClient, IPAddress friendIP, string name, string initialMessage)
 {
     InitializeComponent();
     remoteClient                  = cmdClient;
     targetIP                      = friendIP;
     remoteName                    = name;
     lblPrivateChatName.Text       = name;
     txtMessages.Text              = this.remoteName + ": " + initialMessage + Environment.NewLine;
     remoteClient.CommandReceived += new CommandReceivedEventHandler(private_CommandReceived);
 }
Пример #6
0
        private void LoginToServer()
        {
            if (txtUserName.Text.Trim() == "")
            {
                MessageBox.Show("Nome de usuário está vazio.", "Erro de conexão", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            else
            {
                Client = new CMDClient(GetIPAddress(), GetPortNumber(), "None");
                Client.CommandReceived     += new CommandReceivedEventHandler(CommandReceived);
                Client.ConnectingSuccessed += new ConnectingSuccessedEventHandler(client_ConnectingSuccessed);
                Client.ConnectingFailed    += new ConnectingFailedEventHandler(client_ConnectingFailed);

                Client.NetworkName = txtUserName.Text.Trim();
                Client.ConnectToServer();
            }
        }
        public void VerySimpleTest()
        {
            CMDClient client = new CMDClient(null, "Bogus network name");

            Assert.AreEqual("Bogus network name", client.NetworkName);
        }
Пример #8
0
 public frmMain()
 {
     InitializeComponent();
     this.privateWindowsList = new List <frmPrivate>();
     this.client             = new CMDClient(IPAddress.Parse("127.0.0.1"), 10220, "None");
 }
Пример #9
0
 public frmGroupChat()
 {
     InitializeComponent();
     privateWindowsList = new List <frmPrivateChat>();
     client             = new CMDClient(IPAddress.Parse("127.0.0.1"), 10220, "None");
 }