/*
* 该接口为基础的网络接口,包括了网络服务,服务端接口,客户端接口的基本定义 e.g.
* ⭐INetProvider 网络服务接口的基本定义
* ⭐INetServer 服务端接口的基本定义
* ⭐INetClient 客户端接口的基本定义
*/
using System;
using Cysharp.Threading.Tasks;
namespace BITKit
{
///
/// 网络提供服务,包括了基础网络服务,e.g
/// ⭐向服务器发送指令
/// ⭐向所有客户端发送指令
/// ⭐向单个客户端发送指令
/// ⭐监听与取消监听网络命令
/// ⭐从服务器获取数据
/// ⭐从客户端获取数据
/// ⭐添加Rpc处理服务
/// ⭐向服务器发送Rpc
/// ⭐向所有客户端发送Rpc
///
public interface INetProvider
{
///
/// 向服务端发送指令
///
/// 远程指令类型
void ServerCommand(T command=default);
///
/// 向所有客户端发送指令
///
/// 远程指令类型
void RpcClientCommand(T command=default);
///
/// 向单个客户端发送指令
///
/// 客户端ID
/// 指令实例
/// 远程指令类型
void ClientCommand(int id,T command);
///
/// 从服务端获取数据
///
/// 可寻址路劲 e.g. Key
///
///
UniTask GetFromServer(string addressablePath=Constant.System.Internal);
///
/// 从客户端获取数据
///
/// 客户端ID
/// 可寻址路劲 e.g. Key
/// 远程指令类型
///
UniTask GetFromClient(int id,string addressablePath=Constant.System.Internal);
///
/// 添加RPC远程服务,服务类型为需要的方法标记[RPC]
///
/// RPC服务实例
void AddRpcHandle(object rpcHandle);
///
/// 监听远程指令
///
/// 远程指令回调
/// 远程指令类型
void AddCommandListener(Action handle);
///
/// 取消监听远程指令
///
/// 远程指令回调
/// 远程指令类型
void RemoveCommandListener(Action handle);
///
/// 向服务端发送Rpc
///
/// RPC名称
/// RPC参数
void SendRT(string rpcName, params object[] pars);
///
/// 向指定客户端发送Rpc
///
/// 远程客户端Id
/// RPC名称
/// RPC参数
void SendTargetRT(int id, string rpcName, params object[] pars);
///
/// 向所有客户端发送Rpc
///
/// RPC名称
/// RPC参数
void SendAllRT(string rpcName, params object[] pars);
}
///
/// 服务端接口,支持服务端的基本功能
/// ⭐开启服务器(支持指定端口)
/// ⭐停止服务器
/// ⭐服务器运行状态
///
public interface INetServer
{
///
/// 回调:当客户端连接时
///
public event Action OnClientConnect;
///
/// 回调:当客户端断开连接时
///
public event Action OnClientDisconnected;
///
/// 运行服务端
///
/// 端口,默认为27014
void StartServer(ushort port = 27014);
///
/// 停止服务端
///
/// 可选参数:强行释放,默认为false
void StopServer(bool dispose);
///
/// (只读)服务器是否正在运行
///
bool IsRunningServer { get; }
}
public interface INetClient
{
public event Action OnStartConnect;
public event Action OnConnected;
public event Action OnDisconnected;
public event Action OnConnectedFailed;
UniTask Connect(string address="localhost",ushort port=27014);
bool IsConnected { get; }
int Ping { get; }
void Disconnect();
}
}