Пример #1
0
        private void Client_ServerDisconnected(ClientSide c, string MessageContent)
        {
            MessageBox.Show("Lost connection with server. Bye..");
            this.Invoke((MethodInvoker) delegate {
                // Running on the UI thread

                this.Close();
            });
        }
Пример #2
0
        public Chat(ClientSide c, Color clinetColor, string userName)
        {
            InitializeComponent();
            myColor    = clinetColor;
            myUserName = userName;

            Client     = c;
            this.Text += " - " + myUserName;
            Client.MessageRecieved    += Client_MessageRecieved;
            Client.ServerDisconnected += Client_ServerDisconnected;

            //c.sendMessageToServer(myUserName);
            //t = new Thread(new ThreadStart(c.handleMessagesFromServer));
            //t.Start();
        }
Пример #3
0
        private void Client_MessageRecieved(ClientSide sender, string MessageContent)
        {
            try
            {
                this.ChatListMessages.Invoke((MethodInvoker) delegate {
                    // Running on the UI thread

                    ChatListMessages.Items.Add(MessageContent);
                });
                //Console.WriteLine(e);
            }
            catch
            {
                Console.WriteLine("Error receiving message from server..");
            }
        }
Пример #4
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            _client = new ClientSide();

            if (!_client.Connect(new IPEndPoint(IPAddress.Loopback, 33533)))
            {
                return;
            }

            _client.Connected    += _client_Connected;
            _client.Disconnected += _client_Disconnected;

            //Request GUID from server
            _sender = new Sender();
            _client.ClientSend(_sender.RequestGuid());

            //Enable ping timer :)
            tmrPing.Enabled = true;
        }
Пример #5
0
        private void OkButton1_Click(object sender, EventArgs e)
        {
            string ip       = IpTextBox1.Text;
            int    port     = (int)PortUpDown.Value;
            string UserName = NickNametextBox2.Text;
            //send to clientSide?
            ClientSide Client = new ClientSide(ip, port, ClientColor, UserName);
            //       chatting = new Chat(Client, ClientColor, NickNametextBox2.Text);
            bool res = Client.Connect(ip, port);

            Client.sendMessageToServer(UserName);
            if (!res)
            {
                MessageBox.Show("Cant connect to server");
                return;
            }
            //     ConnectedClients f = new ConnectedClients(ClientColor, UserName.Text, client);
            this.Hide();
            chatting.Show();
        }
Пример #6
0
        public void Start()
        {
            while (true)
            {
                var o = Console.ReadLine()?.Split(' ');
                if (o != null && o[0] == "download")
                {
                    ClientSide.Find(o[1], _nodeCache[0], Directory.GetCurrentDirectory() + "\\Download\\");
                    Logger.Log(Logger.LogLevel.Info, "Download Finish", $"Download a new file {o[1]}");
                }
                else if (o != null && o[0] == "upload")
                {
                    if (o[1] == "-d")
                    {
                        var directory = Directory.EnumerateFiles(o[2]);
                        foreach (var file in directory)
                        {
                            string fileName = Path.GetFileName(file);
                            ClientSide.Send(fileName, file, _nodeCache[0]);
                        }
                        Logger.Log(Logger.LogLevel.Info, "Upload Finish", $"Upload a new directory {o[2]}");
                    }
                    else if (o[1] == "-f")
                    {
                        string path     = o[2];
                        string fileName = Path.GetFileName(path);

                        ClientSide.Send(fileName, path, _nodeCache[0]);
                        Logger.Log(Logger.LogLevel.Info, "Upload Finish", $"Upload a new file {fileName}");
                    }
                }
                else if (o != null && o[0] == "show")
                {
                    var result = ClientSide.GetAllFilesInSystem(_nodeCache[0]);
                    foreach (var file in result)
                    {
                        Console.WriteLine(file);
                    }
                }
            }
        }