public void OnTransportRead(IKcpSession session, ref WrappedReader reader, WrappedArgs args) { int length = (int)reader.Length; var buffer = reader.ReadBuffer(length); //string str = System.Text.Encoding.UTF8.GetString(buffer.FirstSpan); //Console.WriteLine($"频道:{session.Conv},收到消息:{str}" ); }
public override void OnSessionClosed(IKcpSession session) { if (!this.sessions.ContainsKey(session.Conv)) { return; } this.sessions.Remove(session.Conv); }
protected void SendExceptionTo(IKcpSession session, Exception ex) { var kcpSession = session as KcpSession; if (kcpSession == null) { throw new Exception("Unknown session type"); } kcpSession.OnUdpMessageException(ex); }
protected void SendUdpMessageTo(IKcpSession session, ref ReadOnlySequence <byte> buffer) { var kcpSession = session as KcpSession; if (kcpSession == null) { throw new Exception("Unknown session type"); } kcpSession.InputUdpMessage(ref buffer); }
public override void OnTransportActive(IKcpSession session) { base.OnTransportActive(session); M.sessions.Add(session); //int count = 10; //for (int i = 0; i < count; i++) //{ // byte[] bytes = System.Text.Encoding.UTF8.GetBytes("kcp>>>>>>>>>>nihao_" + i.ToString()); // session.SafeSendAsync(bytes); //} //for (int i = 0; i < count; i++) //{ // byte[] bytes = System.Text.Encoding.UTF8.GetBytes("udp>>>>>>>>>>nihao_" + i.ToString()); // session.UnsafeSendAsync(Program.s_address, bytes); //} }
public abstract void OnSessionClosed(IKcpSession session);
public void OnTransportWrite(IKcpSession session, ref WrappedWriter writer, WrappedArgs args) { byte[] bytes = args.Value as byte[]; //Console.WriteLine("kcp pipeline写入数据>>" + bytes.Length); writer.Write(bytes); }
public void OnTransportException(IKcpSession session, Exception ex) { Console.WriteLine(">>>>>>>>>>>>>>>>>" + ex.ToString()); }
public void OnTransportInactive(IKcpSession session) { }
public virtual void OnTransportActive(IKcpSession session) { Console.WriteLine($"{filterName}>>>>>OnTransportActive"); }