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

TCPListener logs

parent b11f0788
...@@ -50,12 +50,15 @@ namespace GatewaySCO ...@@ -50,12 +50,15 @@ namespace GatewaySCO
/// </summary> /// </summary>
public static int LongitudCodificada(byte[] bytesMensaje) 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. // Extrae longitud. Primeros 4 bytes del arreglo.
byte[] bytesLongitudMensaje = new byte[4]; byte[] bytes = new byte[4];
Buffer.BlockCopy(bytesMensaje, 0, bytesLongitudMensaje, 0, 4); Buffer.BlockCopy(bytesMensaje, 0, bytes, 0, 4);
if (BitConverter.IsLittleEndian) if (BitConverter.IsLittleEndian)
Array.Reverse(bytesLongitudMensaje); Array.Reverse(bytes);
int longitud = BitConverter.ToInt32(bytesLongitudMensaje, 0); int longitud = BitConverter.ToInt32(bytes, 0);
return longitud; return longitud;
} }
......
...@@ -7,7 +7,7 @@ using EvaPosSrvAplicacionImp; ...@@ -7,7 +7,7 @@ using EvaPosSrvAplicacionImp;
using EvaPosSrvRespImp; using EvaPosSrvRespImp;
using gatewaySCO.POSBC; using gatewaySCO.POSBC;
using GatewayCHEC.Servidor; using GatewayCHEC.Servidor;
using Servidor.TcpGatewayB; using Servidor.TcpGateway;
namespace GatewaySCO namespace GatewaySCO
{ {
...@@ -24,7 +24,7 @@ namespace GatewaySCO ...@@ -24,7 +24,7 @@ namespace GatewaySCO
ProgramGatewaySCO program = new(); ProgramGatewaySCO program = new();
program.LeeActivaConfiguracion(args); program.LeeActivaConfiguracion(args);
TcpGatewayB gateway = new TcpGatewayB(); TcpGateway gateway = new TcpGateway();
await gateway.Start(); await gateway.Start();
} }
......
...@@ -5,9 +5,9 @@ using System.Text; ...@@ -5,9 +5,9 @@ using System.Text;
using GatewaySCO; using GatewaySCO;
using Serilog; using Serilog;
namespace Servidor.TcpGatewayB; namespace Servidor.TcpGateway;
public class TcpGatewayB public class TcpGateway
{ {
private const int GatewayPort = 6690; private const int GatewayPort = 6690;
private const string PosbcServer = "127.0.0.1"; private const string PosbcServer = "127.0.0.1";
...@@ -86,8 +86,6 @@ public class TcpGatewayB ...@@ -86,8 +86,6 @@ public class TcpGatewayB
private async Task ReceiveFromPosbcAndSendToChecAsync(NetworkStream posbcStream, NetworkStream checStream) private async Task ReceiveFromPosbcAndSendToChecAsync(NetworkStream posbcStream, NetworkStream checStream)
{ {
byte[] buffer = new byte[4096];
while (true) while (true)
{ {
try try
...@@ -98,9 +96,10 @@ public class TcpGatewayB ...@@ -98,9 +96,10 @@ public class TcpGatewayB
if (bytesRead == 0) continue; // Si no se lee nada, continuar esperando if (bytesRead == 0) continue; // Si no se lee nada, continuar esperando
int messageLength = Util.LongitudCodificada(lengthBuffer); 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]; byte[] messageBuffer = new byte[messageLength];
bytesRead = await posbcStream.ReadAsync(messageBuffer, 0, 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 if (bytesRead == 0) continue; // Si no se lee nada, continuar esperando
// Remitir mensaje a CHEC // 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