1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| void TcpReception(object socket)
{
Socket client = (Socket)socket;
byte[] buffer = new byte[528];
try
{
while (networkIsRunning && client.Connected /*&& groundIsRunning*/)
{
// Réception d'un nouveau message
int currentread = 0;
int totalread = 0;
int countzero = 0;
SocketError code = SocketError.Success;
do
{
currentread = client.Receive(buffer, totalread, buffer.Length - totalread, SocketFlags.None, out code);
totalread += currentread;
if (currentread == 0)
{
countzero++; Thread.Sleep(10);
if (countzero > 10) throw new Exception("La connexion " + client.ToString() + " a été perdue.");
}
if (currentread < buffer.Length) WriteLogInformation("Attention : Connection " + client.ToString() + " => Réception de " + totalread + " bytes.");
}
while (totalread < buffer.Length);
}
}
catch (Exception ex)
{
WriteLogInformation(ex);
}
} |
Partager