private void Test_Client_FormClosing(object sender, FormClosingEventArgs e) { if (MessageBox.Show("Are you sure you want to leave the chat room?", "Test Client: " + strServerName, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No) { e.Cancel = true; return; } try { //Send a message to logout of the server Data msgToSend = new Data(); msgToSend.cmdCommand = Command.Logout; msgToSend.strName = strServerName; msgToSend.strMessage = null; byte[] b = msgToSend.ToByte(); clientSocket.Send(b, 0, b.Length, SocketFlags.None); clientSocket.Close(); } catch (ObjectDisposedException) { } catch { } }
private void Form1_Load(object sender, EventArgs e) { this.Text = "Test Client: " + strServerName; //The user has logged into the system so we now request the server to send //the names of all users who are in the chat room Data msgToSend = new Data(); msgToSend.cmdCommand = Command.List; msgToSend.strName = strServerName; msgToSend.strMessage = null; byteData = msgToSend.ToByte(); clientSocket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnSend), null); byteData = new byte[1024]; //Start listening to the data asynchronously clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null); }
private void timer1_Tick(object sender, EventArgs e) { try { Data msgToSend = new Data(); msgToSend.cmdCommand = Command.Pulse; msgToSend.strName = "TEST_CLIENT"; msgToSend.strMessage = "TESTING"; byte[] message; message = msgToSend.ToByte(); clientSocket.BeginSend(message, 0, message.Length, SocketFlags.None, new AsyncCallback(OnSend), null); } catch { } }
private void OnConnect(IAsyncResult ar) { try { clientSocket.EndConnect(ar); //We are connected so we login into the server Data msgToSend = new Data(); msgToSend.cmdCommand = Command.Login; msgToSend.strName = "TEST_CLIENT"; msgToSend.strMessage = null; byte[] b = msgToSend.ToByte(); //Send the message to the server clientSocket.BeginSend(b, 0, b.Length, SocketFlags.None, new AsyncCallback(OnSend), null); } catch { } }
private void btnSend_Click_1(object sender, EventArgs e) { if (txtMessage.Text.Contains("@")) { try { Data msgToSend = new Data(); msgToSend.strName = "TEST_CLIENT"; msgToSend.strMessage = txtMessage.Text; msgToSend.cmdCommand = Command.Command; logging.Logging(string.Format("To Server : {0}\r\nPacket Type : Command\r\nServer : {1}", msgToSend.strMessage, msgToSend.strName)); byte[] byteData = msgToSend.ToByte(); clientSocket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnSend), null); txtMessage.Text = null; } catch { } } else if (txtMessage.Text.Contains("/")) { try { string[] temp = new string[65535]; Data msgToSend = new Data(); msgToSend.strName = "TEST_CLIENT"; if (txtMessage.Text.Contains(" ")) { txtMessage.Text.Replace('/', ' '); temp = txtMessage.Text.Split(' '); } msgToSend.strToUser = temp[0]; for (int i =1; i<temp.Length; i++) { msgToSend.strMessage += temp[i] + " "; } if (msgToSend.strMessage.Length <= 0) return; msgToSend.cmdCommand = Command.PrivateMessage; byte[] byteData = msgToSend.ToByte(); clientSocket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnSend), null); txtMessage.Text = null; } catch { } } else { try { //Fill the info for the message to be send Data msgToSend = new Data(); msgToSend.strName = "TEST_CLIENT"; msgToSend.strMessage = txtMessage.Text; msgToSend.cmdCommand = Command.Message; logging.Logging(string.Format("To Server : {0}\r\nPacket Type : Message\r\nServer : {1}", msgToSend.strMessage, msgToSend.strName)); byte[] byteData = msgToSend.ToByte(); //Send it to the server clientSocket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnSend), null); txtMessage.Text = null; } catch { } } }
private void Test_Client_FormClosing(object sender, FormClosingEventArgs e) { if (MessageBox.Show("Are you sure you want to leave the chat room?", "Test Client: " + strServerName, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No) { e.Cancel = true; return; } try { //Send a message to logout of the server Data msgToSend = new Data (); msgToSend.cmdCommand = Command.Logout; msgToSend.strName = strServerName; msgToSend.strMessage = null; byte[] b = msgToSend.ToByte (); clientSocket.Send(b, 0, b.Length, SocketFlags.None); clientSocket.Close(); } catch (ObjectDisposedException) { } catch { } }
private void Form1_Load(object sender, EventArgs e) { this.Text = "Test Client: " + strServerName; //The user has logged into the system so we now request the server to send //the names of all users who are in the chat room Data msgToSend = new Data (); msgToSend.cmdCommand = Command.List; msgToSend.strName = strServerName; msgToSend.strMessage = null; byteData = msgToSend.ToByte(); clientSocket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnSend), null); byteData = new byte[1024]; //Start listening to the data asynchronously clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), null); }
private void btnSend_Click_1(object sender, EventArgs e) { if (txtMessage.Text.Contains("@")) { try { Data msgToSend = new Data(); msgToSend.strName = "TEST_CLIENT"; msgToSend.strMessage = txtMessage.Text; msgToSend.cmdCommand = Command.Command; logging.Logging(string.Format("To Server : {0}\r\nPacket Type : Command\r\nServer : {1}", msgToSend.strMessage, msgToSend.strName)); byte[] byteData = msgToSend.ToByte(); clientSocket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnSend), null); txtMessage.Text = null; } catch { } } else if (txtMessage.Text.Contains("/")) { try { string[] temp = new string[65535]; Data msgToSend = new Data(); msgToSend.strName = "TEST_CLIENT"; if (txtMessage.Text.Contains(" ")) { txtMessage.Text.Replace('/', ' '); temp = txtMessage.Text.Split(' '); } msgToSend.strToUser = temp[0]; for (int i = 1; i < temp.Length; i++) { msgToSend.strMessage += temp[i] + " "; } if (msgToSend.strMessage.Length <= 0) { return; } msgToSend.cmdCommand = Command.PrivateMessage; byte[] byteData = msgToSend.ToByte(); clientSocket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnSend), null); txtMessage.Text = null; } catch { } } else { try { //Fill the info for the message to be send Data msgToSend = new Data(); msgToSend.strName = "TEST_CLIENT"; msgToSend.strMessage = txtMessage.Text; msgToSend.cmdCommand = Command.Message; logging.Logging(string.Format("To Server : {0}\r\nPacket Type : Message\r\nServer : {1}", msgToSend.strMessage, msgToSend.strName)); byte[] byteData = msgToSend.ToByte(); //Send it to the server clientSocket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnSend), null); txtMessage.Text = null; } catch { } } }
private void OnConnect(IAsyncResult ar) { try { clientSocket.EndConnect(ar); //We are connected so we login into the server Data msgToSend = new Data (); msgToSend.cmdCommand = Command.Login; msgToSend.strName = "TEST_CLIENT"; msgToSend.strMessage = null; byte[] b = msgToSend.ToByte (); //Send the message to the server clientSocket.BeginSend(b, 0, b.Length, SocketFlags.None, new AsyncCallback(OnSend), null); } catch { } }