the c# program listens to multiple connections, it is written as follows
try
{
TcpListener listener = new TcpListener(IPAddress.Any, FixedData.port);
listener.Start();
try
{
while (true)
{
dataForMicros = string.Empty;
TcpClient tcpCliente = listener.AcceptTcpClient();
byte[] byteArray = new byte[1024];
string data = string.Empty;
NetworkStream networkStream = tcpCliente.GetStream();
int bytesRead;
while (data.IndexOf(EndOfTransmission) == -1 && (bytesRead = networkStream.Read(byteArray, 0, byteArray.Length)) != 0)
{
data += Encoding.ASCII.GetString(byteArray, 0, bytesRead);
}
int position = data.IndexOf(StartOfText, 0);
string keepAlive = StartOfHeader + " 0 " + StartOfText + EndOfText + EndOfTransmission;
if (position > 1)
{
if (data == keepAlive)
{
reply = Encoding.ASCII.GetBytes(data);
networkStream.Write(reply, 0, reply.Length);
}
else if (ValidateMessage(data))
{
string processResult = ProcessMessage();
dataForMicros = StartOfHeader + "000000001" + " MESSAGEFC" +
StartOfText + FieldSeparator + "03 " + processResult +
EndOfText + EndOfTransmission;
reply = Encoding.ASCII.GetBytes(dataForMicros);
networkStream.Write(reply, 0, reply.Length);
}
}
networkStream.Close();
}
}
catch (Exception ex)
{
FixedData.LogApi.Error("Error: Exception " +
" Message: " + ex.Message);
}
finally
{
listener.Stop();
}
}