我一直在使用sample( decimal( 5*5 ) ) toString(euros)
来发送和接收服务器到客户端的数据。
我正在使用以下代码
服务器
TCP sockets
客户端
private string SendDataToClient(int currentStationSeq, int nextStationSeq, int SequenceOrder)
{
byte[] byData = System.Text.Encoding.ASCII.GetBytes(String.Format("{0},{1},{2}", currentStationSeq, nextStationSeq, SequenceOrder));
Socket workerSocket = null;
for (int i = 0; i < m_workerSocketList.Count; i++)
{
workerSocket = (Socket)m_workerSocketList[i];
if (workerSocket != null)
{
if (workerSocket.Connected)
{
workerSocket.Send(byData);
}
}
}
}
public void OnDataReceived(IAsyncResult asyn)
{
try
{
SocketPacket theSockId = (SocketPacket)asyn.AsyncState;
int iRx = theSockId.thisSocket.EndReceive(asyn);
char[] chars = new char[iRx + 1];
string szData = new string(chars);
//Console.WriteLine(szData);
string[] arrData = szData.Split(',');
if (arrData.Length == 3)
{
// Some code
}
else if (arrData.Length == 2)
{
// Some Code
}
else if (arrData.Length == 1)
{
}
WaitForData();
}
catch (ObjectDisposedException)
{
System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n");
}
catch (SocketException se)
{
}
}
不能连续发送时,它可以正常工作。但是,如果Server
发送数据的速度比Server
更快,则数据开始在缓冲区中累积。当Client
从缓冲区读取它时,它会从缓冲区读取所有数据,从而破坏了我的逻辑。
我需要像client
向Server
发送数据的内容,它必须等待数据在client
方处理,然后再发送任何新数据。
怎么可能?