C#.net TCP通讯
try { TcpClient = new TcpClient(txtServerIp.Text, int.Parse(txtPort.Text.Trim())); Stream = TcpClient.GetStream(); ClientReader = new StreamReader(Stream); ClientWriter = new StreamWriter(Stream); txtServerIp.Enabled = false; btnConnect.Enabled = false; this.Text = "客户端 " + "正在与" + txtServerIp.Text.Trim() + "连接……"; return; } catch { txtServerIp.Enabled = true; btnConnect.Enabled = true; this.Text = "连接失败……"; //MessageBox.Show("连接失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); }