The problem is with the argument
CInt(clientSocket.ReceiveBufferSize
in invocation of function Read.
Besides that why would you want to read 505196 bytes into an array that can only take 10024 bytes, is this a typo and you wanted to say your bytesFrom buffer was even only 1024 bytes.
Explanation:
If the size of buffer is less than the size parameter of
NetworkStream.Read
function an ArgumentOutOfRange Exception is thrown.
See here:
http://msdn.microsoft.com/en-us/library/system.net.sockets.networkstream.read.aspx[
]
Please make the amount of bytes you want to read smaller or equal to the size of your buffer.
Cheers,
Manfred