Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
byte[] inStream = new byte[10025];
            serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);
            string returndata = System.Text.Encoding.ASCII.GetString(inStream);
            MessageBox.Show(returndata);



I write this code snipet for client listen to server response however,
"An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in System.dll"

How can i fix tihs?
Posted

1 solution

Isn't that obvious? You hard-code some array size to 10025. Why? You should never do it. No wonder, if you try to read some amount of data of some other size, such as (int)clientSocket.ReceiveBufferSize, into your buffer, that buffer may be not big enough.
Apparently, if will be just write if you create it without hard-coding based on required size:
int size
C#
int size = (int)clientSocket.ReceiveBufferSize;
byte[] inStream = new byte[size];
serverStream.Read(inStream, 0, size);
// ...

Good luck.
—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900