예제 #1
0
        public Package ReadPackage(ref int srcOffset, ref int pkgLength, int curBufferSize, byte[] srcBuffer, ByteSocket sock)
        {
            short header = 0;

            while (srcOffset + 4 < curBufferSize)
            {
                header = (short)((srcBuffer[srcOffset] << 8) + srcBuffer[srcOffset + 1]);
                if (header == Package.HEADER)
                {
                    pkgLength = (srcBuffer[srcOffset + 2] << 8) + srcBuffer[srcOffset + 3];
                    break;
                }
                else
                {
                    srcOffset++;
                }
            }

            int dataLeft = curBufferSize - srcOffset;

            if ((pkgLength != 0 && pkgLength < Package.HDR_SIZE) || pkgLength > sock.ReceiveBufferSize)
            {
                return null;
            }

            if (dataLeft >= pkgLength && pkgLength != 0)
            {
                Package pkg = sock.ReceiveUsedPacket;
                pkg.CopyFrom(srcBuffer, srcOffset, 0, pkgLength);
                return pkg;
            }

            return null;
        }
예제 #2
0
        public PackageProcessor(ByteSocket socket, byte[] sBuffer, byte[] rBuffer)
        {
            // TODO: Complete member initialization

            m_sendBuffer = sBuffer;
            m_receiveBuffer = rBuffer;

            Init(socket);

            AsyncReceiveImp();
        }
예제 #3
0
        //protected IPackageReader pkgReader;
        public PackageProcessor(ByteSocket socket)
        {
            // TODO: Complete member initialization

            m_sendBuffer = new byte[m_socket.SendBufferSize];
            m_receiveBuffer = new byte[m_socket.ReceiveBufferSize];

            Init(socket);

            AsyncReceiveImp();
        }
예제 #4
0
파일: Program.cs 프로젝트: W8023Y2014/jsion
        static void Main(string[] args)
        {
            ResourceUtil.ExtractResource("LogConfig.xml", "LogConfig.xml", Assembly.GetAssembly(typeof(Program)));

            ByteSocket bs = new ByteSocket();

            bs.ConnectSuccessHandler += new ByteSocket.ConnectSocketDelegate(bs_ConnectSuccessHandler);

            bs.Connect("192.168.16.119", 20000);

            Console.ReadKey();
        }
예제 #5
0
 private void m_socket_ConnectSuccessHandler(ByteSocket bSock)
 {
     OnConnected(true);
 }
예제 #6
0
 private void m_socket_ConnectFailedHandler(ByteSocket bSock)
 {
     OnConnected(false);
 }
예제 #7
0
 public JSNPkgProcessor(ByteSocket socket, byte[] sBuffer, byte[] rBuffer)
     : base(socket, sBuffer, rBuffer)
 {
 }
예제 #8
0
        protected virtual void Init(ByteSocket socket)
        {
            m_sendingTcp = false;
            m_pkgQueue = new Queue(256);

            //pkgReader = new PackageReader();

            m_socket = socket;

            m_sendAsyncEvent = new SocketAsyncEventArgs();
            m_sendAsyncEvent.UserToken = this;
            m_sendAsyncEvent.SetBuffer(m_sendBuffer, 0, 0);
            m_sendAsyncEvent.Completed += new EventHandler<SocketAsyncEventArgs>(AsyncSendPkgComplete);

            m_receiveAsyncEvent = new SocketAsyncEventArgs();
            m_receiveAsyncEvent.Completed += new EventHandler<SocketAsyncEventArgs>(AsyncReceiveComplete);
        }
예제 #9
0
파일: Program.cs 프로젝트: W8023Y2014/jsion
 static void bs_ConnectSuccessHandler(ByteSocket bSock)
 {
     Console.WriteLine("客户端启动成功...");
     bSock.Sockets.Send(new byte[0]);
 }