Exemplo n.º 1
0
        public void ReadCallback(IAsyncResult ar)
        {
            try
            {
                String content = String.Empty;

                StateObject state = (StateObject)ar.AsyncState;

                if (socket.Connected)
                {
                    int bytesRead = socket.EndReceive(ar);

                    if (bytesRead > 0)
                    {
                        try
                        {
                            foreach (byte[] data in PacketUtility.getDataPackets(state.buffer))
                            {
                                recievedQueue.Add(data);
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Read CallBack Error => {0}", e.Message.ToString());
                        }
                    }
                    state = new StateObject();
                    socket.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error => " + e.Message);
                shutDown();
            }
        }