public static ReadBufferHandle Instance(BufferEnum buffer, int verify, byte[] data = null) { ReadBufferHandle handle = new ReadBufferHandle(null); handle.verify = verify; handle.buffer = buffer; handle.data = data; return(handle); }
//打包请求读取远端数据 public void BunchRequestBuffer(BufferEnum read, IPEndPoint remote, Action <Request, byte[]> succeed, Action <Request> failed) { ReadBufferHandle handle = ReadBufferHandle.Instance(read, RandVerify); //监听请求 BunchRequestAdd(handle, remote, succeed, failed); //Debug.Log("发送请求"); BunchSend(); }
private void OnReadBufferCallback(UdpPoint point, IPEndPoint remote, ReadBufferHandle handle) { byte[] value; if (!ReadBufferDic.TryGetValue(handle.buffer, out value)) { value = new byte[0]; //Debug.Log("读取=>" + handle.buffer +"[没有数据]"+"null"); } else { //Debug.Log("读取=>" + handle.buffer + "[数据大小]"+value.Length); } point.BunchTaskAdd(remote, WriteBufferHandle.Instance(handle.buffer, handle.verify, value)); //point.ReplyCollect(WriteBufferHandle.Instance(handle.buffer, handle.verify, value).ToBytes()); }
/// <summary> /// 请求读取远端数据,返回一条操作 /// 需要指定读取的数据缓存区和远端网络地址 /// 返回的数据会缓存在回调函数的参数里 /// </summary> public void SingleRequestBuffer(BufferEnum read, IPEndPoint remote, Action <Request, byte[]> succeed, Action <Request> failed) { ReadBufferHandle handle = ReadBufferHandle.Instance(read, RandVerify); Request request = new Request(handle, remote, succeed, failed); request.isSend = false; request.overtime = 1000 / FRAME; request.timeSend = TickTime; request.timeStart = TickTime; request.verify = handle.verify; //添加请求列表 if (RequestDic.TryAdd(handle.verify, request)) { Netstat netstat = NetstatDic.GetOrAdd(remote, new Netstat()); netstat.request += 1; //注册完成后直接发送 SendTo(handle.ToBytes(), remote, request); //Debug.Log("[注册验证]" + request.verify + "[验证总数]" + RequestDic.Count); } //Console.WriteLine("单独发送数据请求"+remote + "[ReadBufferHandle]"); //HandleManager.OutStr += "单独发送" + handle.verify + "数据请求至" + remote + "[ReadBufferHandle]" + "\n"; }