📄 client.cs
字号:
using System;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
namespace SmartDeviceApplication5
{
public class Client:SocketBase
{
TcpClient client;
public Client()
{
client = new TcpClient();
}
public Connection StartClient(IPAddress ipaddress,int port)
{
try
{
if ( this.linewnum == 0)
{
client.Connect(ipaddress,port);
this.Connection = new Connection(client.GetStream());
this.linewnum = 1;
this.StartListenAndSend();
}
else
{
client.Connect(ipaddress,port);
this.Connection = new Connection(client.GetStream());
this.linewnum = 1;
}
//this._connections.Add(new Connection(client.GetStream()));
}
catch (SocketException e)
{
if (e.ErrorCode == 10061 )
{
MessageBox.Show("服务器没有启动!");
Application.Exit();
return this.Connection;
}
if (e.ErrorCode == 10056 )
{
client = new TcpClient();
client.Connect(ipaddress,port);
this.Connection = new Connection(client.GetStream());
this.linewnum = 1;
this.StartListenAndSend();
}
}
// MessageBox.Show("连接成功!");
return this.Connection;
}
public void StopClient()
{
this.EndListenAndSend();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -