Answer the question
In order to leave comments, you need to log in
Why does Socket.Receive hang tightly?
static void Main(string[] args)
{
TcpListener myTCP = new TcpListener(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8888));
Console.WriteLine("Запускаю процесс прослушивания...");
while (true)
{
myTCP.Start(); // Запускаю процесс прослушивания
if (myTCP.Pending()) // Если есть запрос
{
Console.WriteLine("Ура, найден запрос!");
using (Socket myClient = myTCP.AcceptSocket()) // То создаю сокет для этого запроса
{
if (myClient.Connected) // Открываю сокет
{
try
{
Console.WriteLine("Открываю сокет для считывания запроса");
string data = "";
byte[] sqlQuery = new byte[myClient.ReceiveBufferSize];
int bytesRec = myClient.Receive(sqlQuery); // Считываю массив байтов в sqlQuery и возвращаю количество считанных байтов
data += Encoding.UTF8.GetString(sqlQuery, 0, bytesRec);
Console.Write("Я попал сюда " + data);
}
catch (SocketException e)
{
Console.WriteLine("{0} Error Code {1}", e.Message, e.ErrorCode);
}
}
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question