private static Socket ConnectSocket(string server, int port)
{
Socket s = null;
IPHostEntry hostEntry = null;
hostEntry = Dns.GetHostEntry(server);
foreach (IPAddress address in hostEntry.AddressList)
{
IPEndPoint ipe = new IPEndPoint(address, port);
Socket tempSocket =
new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
tempSocket.Connect(ipe);
if (tempSocket.Connected)
{
s = tempSocket;
break;
}
else
{
continue;
}
}
return s;
}
//...
Socket s = ConnectSocket(server, port);
//...
do
{
bytes = s.Receive(bytesReceived, bytesReceived.Length, 0); // 1
page = page + Encoding.UTF8.GetString(bytesReceived, 0, bytes); // 2
}
while (bytes == 1024);
That's a "page" circumcised (without end) data.
If between the "/ / 1" and "/ / 2" write System.Threading.Thread.Sleep(100)
, then everything works.