Cba369265a2a38ef302f5458a355454d

This method will read HTTP requests, is this the best way to read a network recieve stream?

private byte[] ReadFully(Socket p_connection)
{            
    Socket connection = p_connection;
    byte[] buffer = new byte[connection.ReceiveBufferSize];

    int received = connection.Receive(buffer);

    Array.Resize(ref buffer, received);

    return buffer;
}

Refactorings

No refactoring yet !

22e33503870d8e20493c4dd6b2f9767f

rikkus

March 21, 2009, March 21, 2009 16:28, permalink

No rating. Login to rate!

If you want to perform an HTTP request, you should use WebRequest:

http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx

Your code is incorrect because it claims to 'read fully' but may, even if there is no error, return less than the 'full' data.

Your refactoring





Format Copy from initial code

or Cancel