"gatewayGK/ComandosPruebas/ReprintReceiptsPosbcCmd.cs" did not exist on "dbe4bfb507611f8685722ecf676100d0ef8fdd64"
Commit 6ad5b3de authored by Jose Hugo Torres's avatar Jose Hugo Torres
Browse files

Gateway #14

parent 494da98c
...@@ -110,10 +110,10 @@ public class ServidorGatewayCHEC(string ipGateway, int ptoGateway, string ipPOSB ...@@ -110,10 +110,10 @@ public class ServidorGatewayCHEC(string ipGateway, int ptoGateway, string ipPOSB
idProceso = Environment.ProcessId; idProceso = Environment.ProcessId;
#endif #endif
Log.Information("Gateway servidor socket en {ip} : {puerto}, proceso id {id}", IpGateway, PuertoGateway, idProceso); Log.Information("Servidor GATEWAY CHEC socket en {ip} : {puerto}, proceso id {id}", IpGateway, PuertoGateway, idProceso);
if (_isDebug) if (_isDebug)
{ {
Log.Debug("Versión framework {version} # 13", Environment.Version); Log.Debug("Versión framework {version} # 14", Environment.Version);
Log.Debug("Tcp Socket configuración:"); Log.Debug("Tcp Socket configuración:");
Log.Debug($" Blocking {tcpSocket.Blocking}"); Log.Debug($" Blocking {tcpSocket.Blocking}");
Log.Debug($" ExclusiveAddressUse {tcpSocket.ExclusiveAddressUse}"); Log.Debug($" ExclusiveAddressUse {tcpSocket.ExclusiveAddressUse}");
...@@ -129,23 +129,23 @@ public class ServidorGatewayCHEC(string ipGateway, int ptoGateway, string ipPOSB ...@@ -129,23 +129,23 @@ public class ServidorGatewayCHEC(string ipGateway, int ptoGateway, string ipPOSB
try try
{ {
//var tareaRecibePOSBC = Task.Run(() => _posbc.Recibe(_canalSalida)); //var tareaRecibePOSBC = Task.Run(() => _posbc.Recibe(_canalSalida));
ActivaPOSBC();
// Procesa conexiones al Gateway. // Procesa conexiones al Gateway.
while (true) while (true)
{ {
Log.Information("Esperando conexión"); Log.Information("Esperando conexión");
Socket clienteCHEC = tcpSocket.Accept(); Socket clienteCHEC = tcpSocket.Accept();
Log.Information("Conexión remota ip {ip} en puerto {pto}", Log.Information("Conexión remota CHEC ip {ip} en puerto {pto}",
IPAddress.Parse(((IPEndPoint)clienteCHEC.RemoteEndPoint).Address.ToString()), IPAddress.Parse(((IPEndPoint)clienteCHEC.RemoteEndPoint).Address.ToString()),
((IPEndPoint)clienteCHEC.RemoteEndPoint).Port.ToString()); ((IPEndPoint)clienteCHEC.RemoteEndPoint).Port.ToString());
// Activa el POSBC // Activa el POSBC
ActivaPOSBC();
var tareaAceptaEntradasCHEC = Task.Run(() => AceptaEntradasCHEC(clienteCHEC));
var tareaRemiteRespuestaPOSBC = Task.Run(() => ProcesaSalidaPOSBC(clienteCHEC, _posbc.Socket)); var tareaRemiteRespuestaPOSBC = Task.Run(() => ProcesaSalidaPOSBC(clienteCHEC, _posbc.Socket));
var tareaAceptaEntradasCHEC = Task.Run(() => AceptaEntradasCHEC(clienteCHEC));
} }
} }
finally finally
{ {
Log.Warning("Servidor GATEWAY CERRADO.");
tcpSocket.Close(); tcpSocket.Close();
_posbc.CierraConexion(); _posbc.CierraConexion();
} }
......
...@@ -30,8 +30,14 @@ public class SocketServer ...@@ -30,8 +30,14 @@ public class SocketServer
// Recibir el mensaje del cliente // Recibir el mensaje del cliente
byte[] buffer = new byte[4096]; byte[] buffer = new byte[4096];
int bytesRead = clientSocket.Receive(buffer); int bytesRead = clientSocket.Receive(buffer);
string message = Encoding.UTF8.GetString(buffer, 0, bytesRead); int longitudMsj = 0;
if (bytesRead > 4 ) {
longitudMsj = Util.LongitudCodificada(buffer);
}
string message = Encoding.UTF8.GetString(buffer, 4, 4 + longitudMsj);
Console.WriteLine($"Mensaje recibido: {message}"); Console.WriteLine($"Mensaje recibido: {message}");
string msjRespuesta = message + " desde POSBC";
buffer = Util.ConvierteEnBufferBytes(msjRespuesta);
// Enviar el mismo mensaje de vuelta al cliente // Enviar el mismo mensaje de vuelta al cliente
clientSocket.Send(buffer, bytesRead, SocketFlags.None); clientSocket.Send(buffer, bytesRead, SocketFlags.None);
...@@ -39,18 +45,18 @@ public class SocketServer ...@@ -39,18 +45,18 @@ public class SocketServer
// Enviar mensajes aleatorios adicionales // Enviar mensajes aleatorios adicionales
Random random = new Random(); Random random = new Random();
int additionalMessages = random.Next(0, 6); // Número aleatorio entre 0 y 5 int additionalMessages = random.Next(0, 3); // Número aleatorio entre 0 y 5
for (int i = 1; i <= additionalMessages; i++) for (int i = 1; i <= additionalMessages; i++)
{ {
int delay = random.Next(100, 5001); // Tiempo de espera aleatorio entre 0.1 y 5 segundos int delay = random.Next(100, 5001); // Tiempo de espera aleatorio entre 0.1 y 5 segundos
Task.Delay(delay).Wait(); // Espera asincrónica Task.Delay(delay).Wait(); // Espera asincrónica
string additionalMessage = $"mensaje aleatorio {i} después de {delay}ms"; string additionalMessage = $"mensaje POSBC aleatorio {i} después de {delay}ms";
byte[] additionalData = Util.ConvierteEnBufferBytes(additionalMessage); byte[] additionalData = Util.ConvierteEnBufferBytes(additionalMessage);
clientSocket.Send(additionalData, SocketFlags.None); clientSocket.Send(additionalData, SocketFlags.None);
Console.WriteLine($"Mensaje adicional enviado: {additionalMessage}"); Console.WriteLine($"Mensaje adicional enviado: {additionalMessage} desde POSBC");
Console.WriteLine(Util.DetalleMensajes(additionalData)); //Console.WriteLine(Util.DetalleMensajes(additionalData));
} }
} }
} }
......
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