0

I am making an application in c#.In that application I am using asynchronous socket communication.I have written code as

byte[] byteData = new byte[1024]; clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref m_EpReceive, new AsyncCallback(OnRceiveCallBack), objReceiverSocketState); 

Here I am getting byteData of variable size means sometime 700 bytes,sometime 276 byte (not fixed). Here I have declared byteData of 1024 size. So my question is that is there any way which can declare the size of byteData to exact amount of data received? (Means suppose i am getting 500 bytes so the size of byteData should be 500.) I also have question that if I have declared size of byteData to 1024 so whether it will wait to get total 1024 bytes or if it got some bytes then it will call the OnRceiveCallBack method? Please help me. Thanks in advance.

1 Answer 1

2

EndReceiveFrom will tell you how much bytes has been been received.

public int EndReceiveFrom( IAsyncResult asyncResult, ref EndPoint endPoint ) 

As MSDN says :

Return Value
Type: System.Int32
If successful, the number of bytes received. If unsuccessful, returns 0.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.