ArgumentOutOfRangeException

klcheah1984

New member
Joined
Nov 13, 2006
Messages
3
Programming Experience
1-3
i try to develop a client/server program. it works fine at the beginning. But when i try to request another data transfer, the exception warning pops up.
ArgumentOutOfRangeException

Here is the command

Dim bytes(client.receivebuffersize) as bytes

nwStream = client.getstream

nwstream.read(bytes, 0, cint(client.receivebuffersize))

This line got error. These command are written within a loop so that both client and server can constantly communicate. But i wonder what is the problem with my code.
 
Doesn't look wrong that, you create the buffer one byte larger than the length of receivebuffersize here, but that don't matter because you can set your buffer as large as you want, only bytes actually read into the buffer matter.

According to the documentation for NetworkStream.Read method and ArgumentOutOfRangeException description the only other cause of this exception not explained by your code is 'error accessing socket'
 
Problem solved

I have solved the problem d. i set the size parameter of this function to bytes.Length. Then the program can run smoothly.


nwStream.Read(bytes, 0, bytes.length)

I jus try out all the possibilities and lucklily i made it. But i wonder why it cause the problem. Haha.....
 
That could not have been the reason. If your receivebuffersize was default 8192 bytes, then you first created a byte array of 8193 elements. Then you asked to Read a maximum of 8192 bytes into that buffer, which fitted the bill, anyway it was one byte less than the capasity. Now you do the same except ask to Read a maximum 8193 bytes into the buffer, which is still outside the range of that exception.
 
Reply

i declare the variable bytes as below:

dim bytes(client.receivebuffersize) as byte

tat's it. then i change the parameter to byte.length...it works immediately. strange!!!
 
Back
Top