The following is the client source code of the synchronous chat program. For some of the processes, refer to the server source code.
Using System;
Using System. Drawing;
Using System. Collections;
Using System. ComponentModel;
Using System. Windows. Forms;
Using System. Data;
Using System. Net;
Using System. Net. Sockets;
Using System. Threading;
Using System. Text;
Namespace chat _ socket_client
{
/// <Summary>
/// Summary of Form1.
/// </Summary>
Public class Form1: System. Windows. Forms. Form
{
Private System. Windows. Forms. Label label4;
Private System. Windows. Forms. Label label3;
Private System. Windows. Forms. Label label2;
Private System. Windows. Forms. Label label1;
Private System. Windows. Forms. Button btnStop;
Private System. Windows. Forms. Button btnSend;
Private System. Windows. Forms. TextBox txtPort;
Private System. Windows. Forms. TextBox txtServer;
Private System. Windows. Forms. RichTextBox rtbSend;
Private System. Windows. Forms. RichTextBox rtbReceive;
Private System. Windows. Forms. StatusBar statusBar1;
Private System. Windows. Forms. Button btnConnect;
Private IPAddress hostIPAddress;
Private IPEndPoint Server;
Private Socket sock;
/// <Summary>
/// Required designer variables.
/// </Summary>
Private System. ComponentModel. Container components = null;
Public Form1 ()
{
//
// Required for Windows Form Designer support
//
InitializeComponent ();
//
// TODO: add Any constructor code after InitializeComponent calls
//
}
/// <Summary>
/// Clear all resources in use.
/// </Summary>
Protected override void Dispose (bool disposing)
{
If (disposing)
{
If (components! = Null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing );
}
# Region code generated by Windows Form Designer