Example #1
0
 private void onWriteHeader(IAsyncResult ar)
 {
     try
     {
         ClientReadInfo writeInfo = (ClientReadInfo)ar.AsyncState;
         m_stream.EndWrite(ar);
         m_stream.BeginWrite(writeInfo.Data, 0, writeInfo.Data.Length, onWriteLocalCallback, null);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Example #2
0
        private void onReadHeader(IAsyncResult ar)
        {
            try
            {
                ClientReadInfo header     = (ClientReadInfo)ar.AsyncState;
                int            objectSize = BitConverter.ToInt32(header.Data, 0);

                header.Data = new Byte[objectSize];

                m_stream.BeginRead(header.Data, 0, objectSize, onReadLocalCallback, header);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #3
0
        private void onRead(IAsyncResult ar)
        {
            try
            {
                OnReadEventArgs eA         = new OnReadEventArgs();
                ClientReadInfo  readObject = (ClientReadInfo)ar.AsyncState;

                eA.Obj = Serializer.Serializer.DeserializeByteArray(readObject.Data);

                m_reading = false;

                m_stream.EndRead(ar);
                onReadUserCallback.Invoke(this, eA);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Example #4
0
        public void BeginRead(onReadEventHandler callback)
        {
            if (m_client.Connected)
            {
                try
                {
                    onReadUserCallback = callback;

                    ClientReadInfo header = new ClientReadInfo();
                    header.Data = new Byte[4];

                    m_reading = true;
                    m_stream.BeginRead(header.Data, 0, 4, onReadHeaderLocalCallback, header);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
Example #5
0
        public void BeginWrite(onWriteEventHandler callback, object obj)
        {
            if (m_client.Connected)
            {
                try
                {
                    ClientReadInfo writeInfo = new ClientReadInfo();
                    writeInfo.Data = Serializer.Serializer.SerializeObject(obj);

                    Byte[] array = BitConverter.GetBytes(writeInfo.Data.Length);

                    onWriteUserCallback = callback;

                    m_writing = true;
                    m_stream.BeginWrite(array, 0, array.Length, onWriteHeaderLocalCallback, writeInfo);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }