當我很快地從客戶端多次發送數據時,我不會在服務器中分別接收這些數據。我收到他們作爲一個大型數據突發。我需要爲每個收到的數據發送回覆。但是我不能這樣做,因爲這些數據會在一個大爆發中加入。我怎樣才能發送每個收到的數據的答覆? 在這裏,在服務器回調方法的代碼:C#接收數據的問題
private void RecieveCallback(IAsyncResult asyncResult)
{
ConnectionInfo connection = (ConnectionInfo)asyncResult.AsyncState;
try
{
int bytesRead = connection.Socket.EndReceive(asyncResult);
if (bytesRead > 0)
{
for (int i = 0; i < bytesRead; i++)
connection.FullBufferReceive.Add(connection.BufferReceive[i]);
if (bytesRead == connection.BufferReceive.Length)
{
connection.Socket.BeginReceive(connection.BufferReceive, 0, connection.BufferReceive.Length, 0,
new AsyncCallback(RecieveCallback), connection);
Console.WriteLine("Bytes recieved -- " + bytesRead + " by " + connection.Id);
}
else
{
Console.WriteLine("Bytes recieved " + bytesRead + " by " + connection.Id);
_serverController.StartProcess(connection);
}
}
else
CloseConnection(connection);
}
catch (Exception e)
{
CloseConnection(connection);
Console.WriteLine(e.ToString());
}
}
問題是?請描述該問題;) – 2011-05-05 18:07:57
客戶端代碼可能會更有用。也許你需要調用'.Flush()'。 – 2011-05-05 18:09:23