///** // * 返回可查找的方法键值 // */ //internal static string GetOnlyID(int ClassID, int ActionID) //{ // //string ClMID = string.Empty; // //int ManagedThreadId = ObjectExtension.Thread.ManagedThreadId; // string guid = StringExtension.GetGuid(); // string clmidmt = string.Concat(guid, ClassID.ToString(), ".", ActionID.ToString()); //$"{ClMID}/{ManagedThreadId}";.Substring(10,21) // return clmidmt; //} internal static DataPacket GetDataPacket(ApiPacket api, string ipPort, bool isServer, bool isAsync) //bool isSend, bool isErr, { if (api == null) { throw new ArgumentException(" ApiPacket 对象不能为空!", nameof(api)); } string msg = api.FormatData(); DataPacket dataPacket = new() { ClassID = api.ClassID, ActionID = api.ActionID, OnlyId = Guid.NewGuid(), //OnlyID = clmidmt, Bytes = api.Bytes, IsSend = true, IsErr = false, IsServer = isServer, IsAsync = isAsync, //IsIpIdea = isIpPort, IpPort = ipPort, Obj = msg, }; return(dataPacket); }
/// <summary> /// 异步发送消息(多服务器协调发送) /// </summary> /// <param name="i">向那个服务器端口发包</param> /// <param name="api">接口调用信息</param> public async Task <TcpResponse> SendAsync(int i, ApiPacket api) { if (i >= ClientFrames.Count) { i = 0; } return(await ClientFrames[i].SendAsync(api)); }
/// <summary> /// 同步发送消息(多服务器协调发送) /// </summary> /// <param name="i">向那个服务器端口发包</param> /// <param name="api">接口调用信息</param> /// <returns>返回数据包</returns> public TcpResponse Send(int i, ApiPacket api) { if (i >= ClientFrames.Count) { i = 0; } return(ClientFrames[i].Send(api)); }
/// <summary> /// 同步发送消息(多服务器协调发送+转发给指定客户端) /// </summary> /// <param name="IpPort">事件处理的服务器</param> /// <param name="api">接口调用信息</param> /// <param name="i">返回成功发送包的下标</param> /// <returns>返回数据包</returns> public TcpResponse SendIpIdea(string IpPort, ApiPacket api, out int i) { i = Interlocked.Increment(ref LockCount); if (ClientFrames.Count - 1 == i) { Interlocked.Add(ref LockCount, -ClientFrames.Count); } if (i >= ClientFrames.Count) { i = 0; } return(ClientFrames[i].SendIpIdea(IpPort, api)); }
/// <summary> /// 异步发送消息(多服务器协调发送+转发给指定客户端) /// </summary> /// <param name="IpPort">事件处理的服务器</param> /// <param name="api">接口调用信息</param> /// <returns>返回数据包,以及下标</returns> public async Task <(TcpResponse, int i)> SendIpIdeaAsync(string IpPort, ApiPacket api) { int i = Interlocked.Increment(ref LockCount); if (ClientFrames.Count - 1 == i) { Interlocked.Add(ref LockCount, -ClientFrames.Count); } if (i >= ClientFrames.Count) { i = 0; } return(await ClientFrames[i].SendIpIdeaAsync(IpPort, api), i); }