Ejemplo n.º 1
0
        private void AcceptSocket(IAsyncResult ar)
        {
            MPEGState state = new MPEGState();

            state.Socket = _socket.EndAccept(ar);

            Console.WriteLine("Incoming TCP socket accepted!");
            state.Socket.BeginReceive(state.Buffer, 0, MPEGState.BufferSize, 0,
                                      new AsyncCallback(OnIncomingData), state);

            _socket.BeginAccept(new AsyncCallback(AcceptSocket), _socket);
        }
Ejemplo n.º 2
0
        private void OnIncomingData(IAsyncResult ar)
        {
            MPEGState state   = (MPEGState)ar.AsyncState;
            Socket    handler = state.Socket;

            int read = handler.EndReceive(ar);

            if (read > 0)
            {
                OnData?.Invoke(this, state.Buffer);
                handler.BeginReceive(state.Buffer, 0, MPEGState.BufferSize, 0,
                                     new AsyncCallback(OnIncomingData), state);
            }
            else
            {
                handler.Close();
            }
        }