private void ReceMsg()
{
while (check)
{
byte[] read = new byte[1024];
netStream = tclient.GetStream();
netStream.Read(read, 0, read.Length);
string Recemsg = Encoding.Unicode.GetString(read,0,read.Length);
this.richTextBoxout.Text = Recemsg;
}
}
private void button1_Click(object sender, EventArgs e)
{
//try
// {
//int port=System.Convert.ToInt32(this.textBoxport.Text);
tclient=new TcpClient();
//tclient.Connect(this.textBoxip.Text.Trim(),port);
tclient.Connect("192.192.1.45",6666);
Thread threadread=new Thread(new ThreadStart(ReceMsg));
threadread.Start();
//}
//catch
//{
MessageBox.Show("无法连接!");
//}
this.butConn.Enabled=false;
this.butDisconn.Enabled=true;
this.butSendMsg.Enabled=true;
}
我用的是C# wince5.0 在pc上可以通讯已经试过,在wince中提示连接超时!