HAARFTE/Assets/DemoGame/GameScript/Hotfix/Network/Server/TcpComponent.cs

97 lines
3.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//using System.Text;
//using System.Threading.Tasks;
//using TouchSocket.Core;
//using TouchSocket.Sockets;
//
//namespace ZC.Network.Client
//{
// public class TcpComponent
// {
// private const string url = "127.0.0.1:7789";
// TcpClient tcpClient;
//
// public TcpComponent()
// {
// tcpClient = new TcpClient();
// tcpClient.Connecting += Connecting;
// tcpClient.Connected += Connected; //成功连接到服务器
// tcpClient.Disconnecting += Disconnecting; //即将从服务器断开连接。此处仅主动断开才有效。
// tcpClient.Disconnected += Disconnected; //从服务器断开连接,当连接不成功时不会触发。
// tcpClient.Received += Received;
//
////载入配置
// tcpClient.Setup(new TouchSocketConfig()
// .SetRemoteIPHost(url)
// .ConfigureContainer(a =>
// {
// a.AddConsoleLogger(); //添加一个日志注入
// }));
// }
//
// public void Connect()
// {
// tcpClient.Connect(); //调用连接,当连接不成功时,会抛出异常。
//
// Result result = tcpClient.TryConnect(); //或者可以调用TryConnect
// if (result.IsSuccess())
// {
// tcpClient.Logger.Info("客户端成功连接");
// tcpClient.Send("RRQM");
// }
// else
// {
// tcpClient.Logger.Info($"客户端成功失败,{result.Message}");
// }
// }
//
// public void Send(string message)
// {
// this.tcpClient.Send(message);
// }
//
// public void Close()
// {
// this.tcpClient.Close();
// }
//
//#region Event
//
// private Task Connecting(ITcpClient client, ConnectingEventArgs e)
// {
// tcpClient.Logger.Info($"即将连接到服务器此时已经创建socket但是还未建立tcp. {e.Message}");
// return EasyTask.CompletedTask;
// }
//
// private Task Connected(ITcpClient client, ConnectedEventArgs e)
// {
// tcpClient.Logger.Info($"成功连接到服务器. {e.State}");
// return EasyTask.CompletedTask;
// }
//
// private Task Disconnecting(ITcpClientBase client, DisconnectEventArgs e)
// {
// tcpClient.Logger.Info($"即将从服务器断开连接。此处仅主动断开才有效. {e.Message}");
// return EasyTask.CompletedTask;
// }
//
// private Task Disconnected(ITcpClientBase client, DisconnectEventArgs e)
// {
// tcpClient.Logger.Info($"从服务器断开连接,当连接不成功时不会触发. {e.Message}");
// return EasyTask.CompletedTask;
// }
//
// public Task Received(TcpClient client, ReceivedDataEventArgs e)
// {
// //从服务器收到信息。但是一般byteBlock和requestInfo会根据适配器呈现不同的值。
// var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);
// tcpClient.Logger.Info($"客户端接收到信息:{mes}");
// return EasyTask.CompletedTask;
// }
//
//#endregion
// }
//
// public class LoginRequest : IRequestInfo
// {
// }
//}