我用socket.send向服务器发送命令,服务器响应我但我无法收到完整的响应 . 缓冲区大小小吗?问题出在哪儿?!!
private void send(string toSend)
{
byte[] data = new byte[8192];
int dataLenght = 0;
string ServerResponse = "";
try
{
data = Encoding.ASCII.GetBytes(toSend);
sock.Send(data);
data = new byte[8192];
dataLenght = 0;
while (sock.Available != 0)
{
// System.Threading.Thread.Sleep(200);
data = new byte[8192];
dataLenght = 0;
dataLenght = sock.Receive(data);
ServerResponse += Encoding.ASCII.GetString(data, 0, dataLenght);
}
txtResponse.Text += toSend + ServerResponse + "\n";
txtResponse.SelectionStart = txtResponse.TextLength;
txtResponse.ScrollToCaret();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
}
}