public static KcpSocket CreateSvr(IPEndPoint iPEndPoint, RawReceiveHandler rawReceiveHandler) { var ks = new KcpSocket(SocketHelper.GetUdpSvrSocket(iPEndPoint), rawReceiveHandler); ks.IPPortLocal = iPEndPoint; return(ks); }
public static KcpSocket CreateClient(IPEndPoint remote, RawReceiveHandler rawReceiveHandler) { var ks = new KcpSocket(SocketHelper.GetUdpClientSocket(), rawReceiveHandler); ks.IPPortLocal = (IPEndPoint)ks._socket.LocalEndPoint; ks.IPPortRemote = remote; return(ks); }
private KcpSvr(IPEndPoint svrIpPort, bool autoOnService = true) { SessionMgr = new KcpSessionManager(); _sock = KcpSocket.CreateSvr(svrIpPort, OnRawReceive); SessionMgr.OnNew = this.OnNew; //SessionMgr_OnNew; SessionMgr.OnKick = this.OnKick; //SessionMgr_OnKick; AutoOnService = autoOnService; _sock.OnUpdate += _sock_OnUpdate; _ = _sock.ReceiveAsyncLoop(); _sock.RunKcpLoop(); }
private KcpClient(IPEndPoint svrIpPort) { KcpSession = KcpSession.CreateClientSession(svrIpPort); _sock = KcpSocket.CreateClient(svrIpPort, OnRawReceive); KcpSession.kcp.SetOutput((data, user) => { if (!KcpSession.Closed) { _ = _sock.UdpSendToAsync(new Memory <byte>(data, 0, size), KcpSession.Peer); } }); _sock.OnUpdate += _sock_OnUpdate; }