Socket怎么接收数据啊?
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(getip()), 10);
socket.Bind(ipe);
socket.Listen(10);
Thread thread = new Thread(new ThreadStart(get));
thread.Start();
我已经监听本地的10端口了,可是要怎么开一个纯种专门接收数据啊,
大家教教我啊!
------解决方案--------------------循环开线程接收
int recvCount;
int availCount;
int income = 0;
byte[] recvBytes = new byte[8*1024];
do
{
availCount = client.Available;
if (income == 0)
{
income++;
continue;
}
if (availCount <= 0 && income> 0)
break;
if (availCount < 8*1024)
{
recvCount = client.Receive(recvBytes, availCount, SocketFlags.None);
}
else
{
recvCount = client.Receive(recvBytes, recvBytes.Length, SocketFlags.None);
}
income++;
data += Encoding.UTF8.GetString(recvBytes, 0, recvCount);
}
while (availCount > 0);