我有这段代码:
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);
}
它完美地工作,从客户端接收数据。 问题是当客户端发送两个数据异步请求时。该 服务器在同一个数组中一起接收数据。 我想知道是否有其他方法可以将数据分开。