I have this code:
void Start(Socket ServerSocket)
{
var socketConnected = ServerSocket.Accept();
var state = new State()
{
socket = socketConnected,
buffer = new byte[2048]
};
ServerSocket.BeginReceive(state.buffer, 0, state.bufferSize, SocketFlags.None, ReadCallBack, state);
}
void ReadCallBack(IAsyncResult result)
{
var state = (State)result.AsyncState;
int readData = state.socket.EndReceive(result);
if(readData > 0)
{
//Do Work
}
state.socket.BeginReceive(state.buffer, 0, state.bufferSize, SocketFlags.None, ReadCallBack, state);
}
It works perfectly, receiving data from a client. The problem is that when the client sends two data asynchronous requests. The server receives data all together in the same array. I would like know if there is another way of doing it so that the data is separated.