在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
.Net 4.5的写法 try // TcpClient client = new TcpClient(ip.Trim(), Convert.ToInt32(port.Trim())); var newmsg = new SerMessage();
var client = new TcpClient(); if (!client.ConnectAsync("remotehost", remotePort).Wait(1000)) { // connection failure }
4.5以前 var client = new TcpClient(); var result = client.BeginConnect("remotehost", this.Port, null, null); var success = result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(1)); if (!success) { throw new Exception("Failed to connect."); } // we have connected client.EndConnect(result);
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论