private void QuitChat()
{
if(connected)
{
try
{
string command = "GONE|" + clientname;
Byte outbytes = System.Text.Encoding.ASCII.GetBytes(command.ToCharArray());
ns.Write(outbytes,0,outbytes.Length);
clientsocket.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
// if(logging)
// logwriter.Close();
if(receive != null && receive.IsAlive)
receive.Abort();
this.Text = "客户端";
connected = false;
}
private void btnSend_Click(object sender, System.EventArgs e)
{
if(connected)
{
try
{
string command = "CHAT|" + clientname+": "+ChatOut.Text+"\r\n";
Byte outbytes = System.Text.Encoding.ASCII.GetBytes(command.ToCharArray());
ns.Write(outbytes,0,outbytes.Length);
//clientsocket.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void btnConnect_Click(object sender, System.EventArgs e)
{
EstablishConnection();
RegisterWithServer();
if(connected)
{
receive = new Thread(new ThreadStart(ReceiveChat));
receive.Start();
}
}
private void btnDisconnect_Click(object sender, System.EventArgs e)
{
QuitChat();
}
}
}