Commit ac503a47 authored by Jose Hugo Torres's avatar Jose Hugo Torres
Browse files

TCPListener logs

parent b11f0788
......@@ -50,12 +50,15 @@ namespace GatewaySCO
/// </summary>
public static int LongitudCodificada(byte[] bytesMensaje)
{
if (bytesMensaje.Length != 4) {
throw new ArgumentException("Longitud arreglo bytes con longitud codificada debe ser 4.");
}
// Extrae longitud. Primeros 4 bytes del arreglo.
byte[] bytesLongitudMensaje = new byte[4];
Buffer.BlockCopy(bytesMensaje, 0, bytesLongitudMensaje, 0, 4);
byte[] bytes = new byte[4];
Buffer.BlockCopy(bytesMensaje, 0, bytes, 0, 4);
if (BitConverter.IsLittleEndian)
Array.Reverse(bytesLongitudMensaje);
int longitud = BitConverter.ToInt32(bytesLongitudMensaje, 0);
Array.Reverse(bytes);
int longitud = BitConverter.ToInt32(bytes, 0);
return longitud;
}
......
......@@ -7,7 +7,7 @@ using EvaPosSrvAplicacionImp;
using EvaPosSrvRespImp;
using gatewaySCO.POSBC;
using GatewayCHEC.Servidor;
using Servidor.TcpGatewayB;
using Servidor.TcpGateway;
namespace GatewaySCO
{
......@@ -24,7 +24,7 @@ namespace GatewaySCO
ProgramGatewaySCO program = new();
program.LeeActivaConfiguracion(args);
TcpGatewayB gateway = new TcpGatewayB();
TcpGateway gateway = new TcpGateway();
await gateway.Start();
}
......
......@@ -5,9 +5,9 @@ using System.Text;
using GatewaySCO;
using Serilog;
namespace Servidor.TcpGatewayB;
namespace Servidor.TcpGateway;
public class TcpGatewayB
public class TcpGateway
{
private const int GatewayPort = 6690;
private const string PosbcServer = "127.0.0.1";
......@@ -86,8 +86,6 @@ public class TcpGatewayB
private async Task ReceiveFromPosbcAndSendToChecAsync(NetworkStream posbcStream, NetworkStream checStream)
{
byte[] buffer = new byte[4096];
while (true)
{
try
......@@ -98,9 +96,10 @@ public class TcpGatewayB
if (bytesRead == 0) continue; // Si no se lee nada, continuar esperando
int messageLength = Util.LongitudCodificada(lengthBuffer);
Log.Debug("Mensajde de POSBC longitud {longitud}", messageLength);
Log.Debug("POSBC bytes cabecera leidos {bytes}, longitud en cabecera {longitud}", bytesRead, messageLength);
byte[] messageBuffer = new byte[messageLength];
bytesRead = await posbcStream.ReadAsync(messageBuffer, 0, messageLength);
Log.Debug("POSBC bytes cuerpo ledidos {bytes}", bytesRead);
if (bytesRead == 0) continue; // Si no se lee nada, continuar esperando
// Remitir mensaje a CHEC
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment