コード例 #1
0
        public override void Dispose()
        {
            base.Dispose();

            foreach (KeyValuePair <long, KChannel> keyValuePair in this.m_LocalConnChannels)
            {
                keyValuePair.Value.Dispose();
            }

            this.m_Socket.Close();
            this.m_Socket = null;
            Instance      = null;
        }
コード例 #2
0
        public KService() : base()
        {
            this.m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            //this.m_Socket.Blocking = false;
            this.m_Socket.Bind(new IPEndPoint(IPAddress.Any, 0));
#if SERVER
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                const uint IOC_IN            = 0x80000000;
                const uint IOC_VENDOR        = 0x18000000;
                uint       SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;
                this.m_Socket.IOControl((int)SIO_UDP_CONNRESET, new[] { Convert.ToByte(false) }, null);
            }
#endif
            Instance = this;
        }
コード例 #3
0
        // Connect
        public KChannel(uint localConn, Socket m_Socket, IPEndPoint m_RemoteEndPoint, KService kService) : base(kService, ChannelType.Connect)
        {
            this.m_MemoryStream   = this.GetService().MemoryStreamManager.GetStream(NetWorkConstant.Str_Msg, ushort.MaxValue);
            this.LocalConn        = localConn;
            this.m_Socket         = m_Socket;
            this.m_RemoteEndPoint = m_RemoteEndPoint;


            this.Connect();
        }
コード例 #4
0
        // Accept
        public KChannel(uint localConn, uint remoteConn, Socket m_Socket, IPEndPoint m_RemoteEndPoint, KService kService) : base(kService, ChannelType.Accept)
        {
            this.m_MemoryStream = this.GetService().MemoryStreamManager.GetStream(NetWorkConstant.Str_Msg, ushort.MaxValue);

            this.LocalConn        = localConn;
            this.RemoteConn       = remoteConn;
            this.m_RemoteEndPoint = m_RemoteEndPoint;
            this.m_Socket         = m_Socket;
            this.m_Kcp            = Kcp.KcpCreate(this.RemoteConn, new IntPtr(this.LocalConn));


            ///Kcp 参数
            SetOutput();
            Kcp.KcpNodelay(this.m_Kcp, 1, 10, 1, 1);
            Kcp.KcpWndsize(this.m_Kcp, 256, 256);
            Kcp.KcpSetmtu(this.m_Kcp, 470);
            ///



            this.Accept();
        }
コード例 #5
0
 public static int KcpOutput(IntPtr bytes, int len, IntPtr m_Kcp, IntPtr user)
 {
     KService.Output(bytes, len, user);
     return(len);
 }