privatevoidtcpStart_Click(objectsender,EventArgse)//打开TCP连接{//IPAddressipAddr=IPAddress.Parse("172.24.54.19");IPAddressipAddr=IPAddress.Parse(IP);IPEndPointipEnd=newI...
private void tcpStart_Click(object sender, EventArgs e) //打开TCP连接
{
//IPAddress ipAddr = IPAddress.Parse("172.24.54.19");
IPAddress ipAddr = IPAddress.Parse(IP);
IPEndPoint ipEnd = new IPEndPoint(ipAddr, 9603);
//创建socket实例
try
{
socket.Connect(ipEnd);
btnStart.Enabled = true;
MessageBox.Show("TCP连接成功!!");
}
catch
{
MessageBox.Show("TCP连接失败!!");
}
}
private void tcpStop_Click(object sender, EventArgs e) //关闭TCP连接
{
try
{
socket.Shutdown(SocketShutdown.Both);
socket.Close();
//socket.Disconnect(true);
btnStart.Enabled = false;
btnStop.Enabled = false;
MessageBox.Show("Socket连接关闭!!");
}
catch
{
MessageBox.Show("Socket连接关闭异常!!");
}
}
这是我写的打开和关闭TCP连接的代码,各位大神们帮忙看看是哪里出了问题,需要怎么修改?谢谢!!!
展开