日期:2014-05-17 浏览次数:20841 次
try
{
socketConnection = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress ipa = IPAddress.Parse(txtIP.Text.Trim());
endpoint = new IPEndPoint(ipa, int.Parse(txtPort.Text.Trim()));
socketConnection.Connect(endpoint);
threadWatch = new Thread(connectionRec);
threadWatch.IsBackground = true;
threadWatch.Start();
}
catch (SocketException ex)
{
do
{
socketConnection.Connect(endpoint);
} while (socketConnection.Connected == false);
threadWatch = new Thread(connectionRec);
threadWatch.IsBackground = true;
threadWatch.Start();
}
catch (Exception ex)
{
MessageBox.Show(ex + "");
}
//可以参考一下这个,有一些异常提示你可以删除掉,就不会弹对话框。
public void link()
{
IPAddress ipRemote;
string ip = ConfigurationManager.AppSettings["MainMachine"].ToString();
string ipport = ConfigurationManager.AppSettings["MainMachinePort"].ToString();
tr