private async void textBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { await SocketHelper.SendChatMessage(textBox.Text); textBox.Text = null; } }
public ChatForm(SocketHelper socketHelper) { SocketHelper = socketHelper; InitializeComponent(); chatList.SelectedIndex = 0; UsernameLabel.Text = socketHelper.Username; PingThread = new Thread(PingPong); PingThread.Start(); }
private async Task <int> Login() { ToggleBlockInterface(); if (Username.Text.Length < 4) { MessageBox.Show("El nom d'usuari es molt curt!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ToggleBlockInterface(); return(-1); } int port = 0; try { port = int.Parse(textPort.Text); } catch (Exception) { MessageBox.Show("El port ha de ser un nĂºmero!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ToggleBlockInterface(); return(-2); } socketHelper = new SocketHelper { Username = Username.Text, ServerIp = textIp.Text, ServerPort = port }; if (await socketHelper.Connect()) { await socketHelper.Login(); Program.ChatForm = new ChatForm(socketHelper); this.Hide(); Program.ChatForm.Show(); return(1); } MessageBox.Show("El servidor no esta obert!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ToggleBlockInterface(); return(2); }
public void End() { PingThread.Abort(); SocketHelper.EndConnection(); Program.LoginForm.Close(); }
public async void SelectChatroom(string roomname) { messageList.Items.Clear(); await SocketHelper.ChangeRoom(roomname); }