コード例 #1
0
ファイル: PacketReader.cs プロジェクト: W8023Y2014/jsion
        public PacketReader(JSocket socket, byte[] buffer)
        {
            m_socket = socket;
            m_buffer = buffer;

            ConfigPkg = m_socket.UsedPacket;
            m_cryptor = m_socket.ReceiveCryptor;
            if (m_cryptor == null) m_cryptor = new NoneCryptor();

            m_receiveAsyncEvent = new SocketAsyncEventArgs();

            m_receiveAsyncEvent.Completed += new EventHandler<SocketAsyncEventArgs>(receiveAsyncEvent_Completed);
        }
コード例 #2
0
ファイル: PacketSender.cs プロジェクト: W8023Y2014/jsion
        public PacketSender(JSocket socket, byte[] buffer)
        {
            m_socket = socket;
            m_buffer = buffer;
            m_pkgQueue = new Queue();

            m_cryptor = m_socket.SendCryptor;
            if (m_cryptor == null) m_cryptor = new NoneCryptor();

            m_sendAsyncEvent = new SocketAsyncEventArgs();
            m_sendAsyncEvent.UserToken = this;
            m_sendAsyncEvent.SetBuffer(m_buffer, 0, 0);
            m_sendAsyncEvent.Completed += new EventHandler<SocketAsyncEventArgs>(sendAsyncEvent_Completed);
        }
コード例 #3
0
        private static void sendAsyncImp(object state)
        {
            PacketSender ps     = state as PacketSender;
            JSocket      socket = ps.m_socket;

            try
            {
                sendAsyncEvent_Completed(socket.Socket, ps.m_sendAsyncEvent);
            }
            catch (Exception ex)
            {
                log.Error("Async send package error.", ex);
                socket.Disconnect();
            }
        }
コード例 #4
0
ファイル: PacketReader.cs プロジェクト: W8023Y2014/jsion
        public PacketReader(JSocket socket, byte[] buffer)
        {
            m_socket = socket;
            m_buffer = buffer;

            ConfigPkg = m_socket.UsedPacket;
            m_cryptor = m_socket.ReceiveCryptor;
            if (m_cryptor == null)
            {
                m_cryptor = new NoneCryptor();
            }

            m_receiveAsyncEvent = new SocketAsyncEventArgs();

            m_receiveAsyncEvent.Completed += new EventHandler <SocketAsyncEventArgs>(receiveAsyncEvent_Completed);
        }
コード例 #5
0
ファイル: GameConnecter.cs プロジェクト: W8023Y2014/jsion
        public object SetSocketType(Message msg)
        {
            Type type = msg.WParam as Type;
            if (type == null)
            {
                throw new ArgumentException("msg.WParam 参数必需为类的Type对象");
            }

            m_socket = type.Assembly.CreateInstance(type.FullName) as JSocket;

            if (m_socket == null)
            {
                throw new ArgumentException("msg.WParam 参数必需为继续JSocket的类的Type对象");
            }

            return null;
        }
コード例 #6
0
        public PacketSender(JSocket socket, byte[] buffer)
        {
            m_socket   = socket;
            m_buffer   = buffer;
            m_pkgQueue = new Queue();

            m_cryptor = m_socket.SendCryptor;
            if (m_cryptor == null)
            {
                m_cryptor = new NoneCryptor();
            }

            m_sendAsyncEvent           = new SocketAsyncEventArgs();
            m_sendAsyncEvent.UserToken = this;
            m_sendAsyncEvent.SetBuffer(m_buffer, 0, 0);
            m_sendAsyncEvent.Completed += new EventHandler <SocketAsyncEventArgs>(sendAsyncEvent_Completed);
        }
コード例 #7
0
 public SocketConnecter(JSocket socket)
 {
     m_socket = socket;
 }
コード例 #8
0
ファイル: SocketConnecter.cs プロジェクト: W8023Y2014/jsion
 public SocketConnecter(JSocket socket)
 {
     m_socket = socket;
 }
コード例 #9
0
ファイル: GameConnecter.cs プロジェクト: W8023Y2014/jsion
 void m_socket_ConnectedSuccess(JSocket socket)
 {
     CreateAndSendMsg(NetMsg.Connected, null, socket);
 }
コード例 #10
0
ファイル: GameConnecter.cs プロジェクト: W8023Y2014/jsion
 void m_socket_ConnectedFaild(JSocket socket)
 {
     CreateAndSendMsg(NetMsg.Errored, null, socket);
 }
コード例 #11
0
ファイル: SocketAccepter.cs プロジェクト: W8023Y2014/jsion
 public SocketAccepter(JSocket socket)
 {
     m_socket = socket;
 }
コード例 #12
0
        private static void sendAsyncEvent_Completed(object sender, SocketAsyncEventArgs e)
        {
            PacketSender   ps      = (PacketSender)e.UserToken;
            JSocket        socket  = ps.m_socket;
            Queue          q       = ps.m_pkgQueue;
            IPacketCryptor cryptor = ps.m_cryptor;
            int            sended  = e.BytesTransferred;

            byte[] data  = ps.m_buffer;
            int    count = ps.m_sendingLength - sended;

            if (count > 0)
            {
                Array.Copy(data, sended, data, 0, count);
            }
            else
            {
                count = 0;
            }

            e.SetBuffer(0, 0);

            int dataOffset = ps.m_lastPkgReadOffset;

            try
            {
                lock (q.SyncRoot)
                {
                    while (q.Count > 0)
                    {
                        Packet pkg = (Packet)q.Peek();

                        int len = 0;

                        if (dataOffset == 0)
                        {
                            cryptor.Encrypt(pkg.Buffer, pkg.Length);
                        }

                        len = pkg.CopyTo(data, count, dataOffset);

                        dataOffset += len;
                        count      += len;

                        if (pkg.Length <= dataOffset)
                        {
                            q.Dequeue();
                            dataOffset = 0;
                            //cryptor.Decrypt(pkg.Buffer, pkg.Length);
                            cryptor.Update();
                        }

                        if (data.Length == count)
                        {
                            break;
                        }
                    }

                    ps.m_lastPkgReadOffset = dataOffset;

                    if (count <= 0)
                    {
                        ps.m_sendingTcp = false;
                        return;
                    }
                }

                ps.m_sendingLength = count;

                e.SetBuffer(0, count);

                if (socket.Socket.SendAsync(e) == false)
                {
                    sendAsyncEvent_Completed(sender, e);
                }
            }
            catch (Exception ex)
            {
                log.Error("Async sending package error.", ex);
                socket.Disconnect();
            }
        }
コード例 #13
0
ファイル: SocketAccepter.cs プロジェクト: W8023Y2014/jsion
 public SocketAccepter(JSocket socket)
 {
     m_socket = socket;
 }