Esempio n. 1
0
        public static KcpSocket CreateSvr(IPEndPoint iPEndPoint, RawReceiveHandler rawReceiveHandler)
        {
            var ks = new KcpSocket(SocketHelper.GetUdpSvrSocket(iPEndPoint), rawReceiveHandler);

            ks.IPPortLocal = iPEndPoint;
            return(ks);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
File: KcpSvr.cs Progetto: sgf/mkcp
        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();
        }
Esempio n. 4
0
 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;
 }