This commit is contained in:
sc committed 2024-11-18 23:51:34 +08:00
commit 6e2b9c2264
2 files changed
+56 -20

No files matched your search

+4 -18
View File
@@ -30,9 +30,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
/// </summary>
public class AsyncTcpClient
{
public async Task TcpClient(string ip,string port)
public static async Task TcpClient(TcpClient tcpClient, string ip,string port)
{
TcpClient tcpClient = new TcpClient();
//TcpClient tcpClient = new TcpClient();
tcpClient.Connecting = (client, e) => { return EasyTask.CompletedTask; };//即将连接到服务器,此时已经创建socket,但是还未建立tcp
tcpClient.Connected = (client, e) => { return EasyTask.CompletedTask; };//成功连接到服务器
tcpClient.Closing = (client, e) => { return EasyTask.CompletedTask; };//即将从服务器断开连接。此处仅主动断开才有效。
@@ -51,28 +51,14 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
.SetRemoteIPHost(ip+":"+port)
.ConfigureContainer(a =>
{
a.AddConsoleLogger();//添加一个日志注入
// a.AddConsoleLogger();//添加一个日志注入
}));
await tcpClient.ConnectAsync();//调用连接,当连接不成功时,会抛出异常。
Result result = await tcpClient.TryConnectAsync();//或者可以调用TryConnectAsync
if (result.IsSuccess())
{
}
tcpClient.Logger.Info("客户端成功连接");
await tcpClient.ConnectAsync();//调用连接,当连接不成功时,会抛出异常。
}
// public Task SendAsync(string id, ReadOnlyMemory<byte> memory);
// public Task SendAsync(string id, IRequestInfo requestInfo);
}
}