chat afbrudt
Jeg har lavet dette lille chat programHvordan for jeg den til at sende en besked hvis forbindelsen bliver afbrudt
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace WindowsApplication8
{
public partial class Form1 : Form
{
private TcpClient client;
private StreamReader rdr;
private StreamWriter wrt;
public Form1()
{
InitializeComponent();
client = new TcpClient("localhost", 1234);
rdr = new StreamReader(client.GetStream());
wrt = new StreamWriter(client.GetStream());
(new Thread(new ThreadStart(Reader))).Start();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Reader()
{
string line;
while ((line = rdr.ReadLine()) != null)
{
lock (msgs)
{
msgs.Text += ("dig: " + line + "\r\n");
}
}
}
private void button1_Click(object sender, EventArgs e)
{
wrt.WriteLine(sendmsg.Text);
wrt.Flush();
lock (msgs)
{
msgs.Text += ("mig: " + sendmsg.Text + "\r\n");
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
//MessageBox.Show("text");
rdr.Close();
wrt.Close();
client.Close();
Application.Exit();
}
}
}