BF2Statistics.Gamespy.Net.GamespyTcpStream.BeginReceive C# (CSharp) Method

BeginReceive() public method

Begins the process of receiving a message from the client. This method must manually be called to Begin receiving data
public BeginReceive ( ) : void
return void
        public void BeginReceive()
        {
            try
            {
                if (Connection != null)
                {
                    // Reset Buffer offset back to the original allocated offset
                    BufferDataToken token = ReadEventArgs.UserToken as BufferDataToken;
                    ReadEventArgs.SetBuffer(token.BufferOffset, token.BufferBlockSize);

                    // Begin Receiving
                    if (!Connection.ReceiveAsync(ReadEventArgs))
                        ProcessReceive();
                }
            }
            catch (ObjectDisposedException e)
            {
                if (!DisconnectEventCalled)
                {
                    // Uh-Oh. idk how we got here
                    Program.ErrorLog.Write("WARNING: [GamespyStream.BeginReceive] ObjectDisposedException was thrown: " + e.Message);

                    // Disconnect user
                    DisconnectEventCalled = true;
                    if (OnDisconnect != null)
                        OnDisconnect();
                }
            }
            catch (SocketException e)
            {
                HandleSocketError(e.SocketErrorCode);
            }
        }

Usage Example

        /// <summary>
        /// Constructor
        /// </summary>
        public GpcmClient(GamespyTcpStream ConnectionStream, int ConnectionId)
        {
            // Set default variable values
            PlayerNick = "Connecting...";
            PlayerId = 0;
            RemoteEndPoint = (IPEndPoint)ConnectionStream.RemoteEndPoint;
            Disposed = false;
            Status = LoginStatus.None;

            // Set the connection ID
            this.ConnectionId = ConnectionId;

            // Create our Client Stream
            Stream = ConnectionStream;
            Stream.OnDisconnect += Stream_OnDisconnect;
            Stream.DataReceived += Stream_DataReceived;
            Stream.BeginReceive();
        }
All Usage Examples Of BF2Statistics.Gamespy.Net.GamespyTcpStream::BeginReceive