try
{
int port = Convert.ToInt32(txtPortNumber.Text);
string host = txtServerIP.Text;
IPAddress ip = IPAddress.Parse(host);
IPEndPoint ipe = new IPEndPoint(ip, port);//把ip和端口转化为IPEndPoint实例
Socket c = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);//创建一个Socket
c.Connect(ipe);//连接到服务器
//c.SendFile(@"C:\数据库升级\aaa.txt");
//c.Shutdown(SocketShutdown.Both);
MessageBox.Show("连接服务器成功!","提示");//显示服务器返回信息
c.Close();
}
catch (ArgumentNullException ex)
{
MessageBox.Show("ArgumentNullException: "+ex);
}
catch (SocketException ex)
{
MessageBox.Show("SocketException: " +ex);
}
通过ip地址及端口连接服务器
最新推荐文章于 2024-04-18 07:15:00 发布