using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Net.Sockets;using System.Net;using System.Threading;using System.IO;
using System.Windows.Forms;
namespace SocketConnTimeOut{ public partial class Form1 : Form { public Form1() { InitializeComponent(); }
private void label2_Click(object sender, EventArgs e) {
} string strIP = ""; int strPort = 8000; int timeout = 1000; private void btnConn_Click(object sender, EventArgs e) { try { strIP = txtIP.Text; strPort = Convert.ToInt32(txtPort.Text);
IPAddress localAddr = IPAddress.Parse(strIP); IPEndPoint remoteEndPoint = new IPEndPoint(localAddr, strPort); TcpClient NetworkClient = TimeOutSocket.Connect(remoteEndPoint, timeout); } catch (Exception ex) { MessageBox.Show("连接失败"); } } }}