日期:2014-05-17 浏览次数:20919 次
TcpClient tcpClient;
BackgroundWorker bgWorkder = new BackgroundWorker();
if (tcpClient != null)
{
tcpClient.Close();
tcpClient=null;
}
try
{
IPAddress ip = IPAddress.Parse(txtIp.Text);
IPEndPoint ipPoint = new IPEndPoint(ip, Convert.ToInt16(txtPort.Text));
tcpClient = new TcpClient();
tcpClient.Connect(ipPoint);
NetworkStream nStream = tcpClient.GetStream();
nStream.Write(bytTotal, 0, bytTotal.Length);
}
catch(System.Net.Sockets.SocketException ex)
{
MessageBox.Show("连接失败!");
BaseTool.LogError(ex);
return;
}
catch (Exception ex)
{
BaseTool.LogError(ex);
MessageBox.Show("未知异常:" + ex.Message);
return;
}
bgWorkder.CancelAsync();
bgWorkder.Dispose();
bgWorkder = new BackgroundWorker();
bgWorkder.WorkerSupportsCancellation = true;
&n