C# 聊天 服务器怎么转发给其他客户端(最好能用集合!) 求~~~
本帖最后由 a398613391 于 2011-11-27 12:24:52 编辑
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.FormClosing += new FormClosingEventHandler(Form1_FormClosing);
}
TcpClient newclient=null ;
Thread nth=null ;
Boolean star = true ;
Thread rd=null ;
NetworkStream ns = null;
BinaryReader nsr = null;
BinaryWriter nsw = null;
public static IPAddress localaddr = IPAddress.Parse("127.0.0.1");
TcpListener listener = new TcpListener(localaddr ,8888);
private void button1_Click(object sender, EventArgs e)
{
listener.Start();
textBox1.Text = "服务器启动";
nth = new Thread(new ThreadStart (clientconnect ));
nth.Start();
}
private void clientconnect()
{
int count=1;
while (star)
{
try
{
newclient = listener.AcceptTcpClient();
textBox1.Text = textBox1.Text+"有"+count +"个客户连接了!\n";
}
catch { }
&