TcpNetCommunicationConnectServerAsync 方法 |
尝试连接远程的服务器,如果连接成功,就切换短连接模式到长连接模式,后面的每次请求都共享一个通道,使得通讯速度更快速
Try to connect to a remote server. If the connection is successful, switch the short connection mode to the long connection mode.
Each subsequent request will share a channel, making the communication speed faster.
命名空间:
HslCommunication.Core.Net
程序集:
HslCommunication (在 HslCommunication.dll 中) 版本:12.1.2.0 (12.1.2.0)
语法 public Task<OperateResult> ConnectServerAsync()
Public Function ConnectServerAsync As Task(Of OperateResult)
public:
Task<OperateResult^>^ ConnectServerAsync()
member ConnectServerAsync : unit -> Task<OperateResult>
返回值
类型:
TaskOperateResult返回连接结果,如果失败的话(也即IsSuccess为False),包含失败信息
示例
简单的连接示例,调用该方法后,连接设备,创建一个长连接的对象,后续的读写操作均公用一个连接对象。
如果想知道是否连接成功,请参照下面的代码。
OperateResult connect = client.ConnectServer( );
if (connect.IsSuccess)
{
Console.WriteLine( "connect success" );
}
else
{
Console.WriteLine( "connect failed" );
}
参见