Commit 7be3dce9 authored by Brayan Sarmiento's avatar Brayan Sarmiento
Browse files

Ciclo completo de inicio de sesion

En este commit se realizo el ciclo completo de chec para iniciar sesion.
parent dbe4bfb5
...@@ -51,11 +51,15 @@ namespace gatewayGK.POSBC ...@@ -51,11 +51,15 @@ namespace gatewayGK.POSBC
socket.Connect(endPoint); socket.Connect(endPoint);
Log.Information("Conectandose al servidor POSBC"); Log.Information("Conectandose al servidor POSBC");
// Enviar los datos // Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None); socket.Send(bufferRecibido, SocketFlags.None);
Log.Information($"Buffer de entrada enviado al servidor POSBC {bufferRecibido}"); Log.Information($"Buffer de entrada enviado al servidor POSBC {bufferRecibido}");
// Buffer para recibir la respuesta - Revisar cual es la mejor manera de recibir ese
// Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 10000;
// Buffer para recibir la respuesta - Revisar cual es la mejor manera de recibir ese
List<byte> receivedBytes = new List<byte>(); List<byte> receivedBytes = new List<byte>();
byte[] bufferSalida = new byte[1024]; byte[] bufferSalida = new byte[1024];
...@@ -63,7 +67,19 @@ namespace gatewayGK.POSBC ...@@ -63,7 +67,19 @@ namespace gatewayGK.POSBC
while (true) while (true)
{ {
int bytesLeidos = 0; int bytesLeidos = 0;
bytesLeidos = socket.Receive(bufferSalida, 0, bufferSalida.Length, SocketFlags.None); try
{
bytesLeidos = socket.Receive(bufferSalida, 0, bufferSalida.Length, SocketFlags.None);
}
catch (SocketException ex)
{
if (ex.SocketErrorCode == SocketError.TimedOut)
{
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
//Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0 //Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0
if (bytesLeidos == 0 || bytesLeidos == 1) if (bytesLeidos == 0 || bytesLeidos == 1)
{ {
...@@ -84,24 +100,6 @@ namespace gatewayGK.POSBC ...@@ -84,24 +100,6 @@ namespace gatewayGK.POSBC
string result = Encoding.UTF8.GetString(data); string result = Encoding.UTF8.GetString(data);
Entorno<EntornoPOSBC>.Instancia.get().BufferSalida = data; Entorno<EntornoPOSBC>.Instancia.get().BufferSalida = data;
//buffer de salida del POSBC
//byte[] bufferSalida = new byte[3048];
//int bytesLeidos = 0;
//bytesLeidos = socket.Receive(bufferSalida, bytesLeidos, bufferSalida.Length, SocketFlags.None);
//string pasarXml = Encoding.UTF8.GetString(bufferSalida, 0, bytesLeidos);
//Log.Information($"Xml Armado {pasarXml}");
//byte[] datosRecibidos = new byte[bytesLeidos];
//// Copiar los datos recibidos al nuevo array
//Array.Copy(bufferSalida, datosRecibidos, bytesLeidos);
//// Convertir los datos recibidos a una cadena
//bufferSalida = datosRecibidos;
////string response = Encoding.UTF8.GetString(buffer, 0, bytesReceived);
//Log.Information($"buffer de salida recibido del POSBC {bufferSalida}");
//Entorno<EntornoPOSBC>.Instancia.get().BufferSalida = bufferSalida;
// Cerrar el socket // Cerrar el socket
socket.Shutdown(SocketShutdown.Both); socket.Shutdown(SocketShutdown.Both);
socket.Close(); socket.Close();
......
...@@ -50,8 +50,10 @@ namespace gatewayGK.POSBC ...@@ -50,8 +50,10 @@ namespace gatewayGK.POSBC
// Enviar los datos // Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None); socket.Send(bufferRecibido, SocketFlags.None);
Log.Information($"Buffer de entrada enviado al servidor POSBC {bufferRecibido}"); Log.Information($"Buffer de entrada enviado al servidor POSBC {bufferRecibido}");
// Buffer para recibir la respuesta - Revisar cual es la mejor manera de recibir ese // Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
// Buffer para recibir la respuesta - Revisar cual es la mejor manera de recibir ese
List<byte> receivedBytes = new List<byte>(); List<byte> receivedBytes = new List<byte>();
byte[] bufferSalida = new byte[1024]; byte[] bufferSalida = new byte[1024];
...@@ -59,7 +61,19 @@ namespace gatewayGK.POSBC ...@@ -59,7 +61,19 @@ namespace gatewayGK.POSBC
while (true) while (true)
{ {
int bytesLeidos = 0; int bytesLeidos = 0;
bytesLeidos = socket.Receive(bufferSalida, 0, bufferSalida.Length, SocketFlags.None); try
{
bytesLeidos = socket.Receive(bufferSalida, 0, bufferSalida.Length, SocketFlags.None);
}
catch(SocketException ex)
{
if (ex.SocketErrorCode == SocketError.TimedOut)
{
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
//Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0 //Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0
if (bytesLeidos == 0 || bytesLeidos == 1) if (bytesLeidos == 0 || bytesLeidos == 1)
{ {
......
...@@ -10,6 +10,7 @@ using System.Net.Sockets; ...@@ -10,6 +10,7 @@ using System.Net.Sockets;
using System.Net; using System.Net;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Threading;
namespace gatewayGK.POSBC namespace gatewayGK.POSBC
{ {
...@@ -49,8 +50,10 @@ namespace gatewayGK.POSBC ...@@ -49,8 +50,10 @@ namespace gatewayGK.POSBC
// Enviar los datos // Enviar los datos
socket.Send(bufferRecibido, SocketFlags.None); socket.Send(bufferRecibido, SocketFlags.None);
Log.Information($"Buffer de entrada enviado al servidor POSBC {bufferRecibido}"); Log.Information($"Buffer de entrada enviado al servidor POSBC {bufferRecibido}");
// Buffer para recibir la respuesta - Revisar cual es la mejor manera de recibir ese // Configurar timeout para el socket (por ejemplo, 5 segundos)
socket.ReceiveTimeout = 5000; // en milisegundos
// Buffer para recibir la respuesta - Revisar cual es la mejor manera de recibir ese
List<byte> receivedBytes = new List<byte>(); List<byte> receivedBytes = new List<byte>();
byte[] bufferSalida = new byte[1024]; byte[] bufferSalida = new byte[1024];
...@@ -58,9 +61,21 @@ namespace gatewayGK.POSBC ...@@ -58,9 +61,21 @@ namespace gatewayGK.POSBC
while (true) while (true)
{ {
int bytesLeidos = 0; int bytesLeidos = 0;
bytesLeidos = socket.Receive(bufferSalida, 0, bufferSalida.Length, SocketFlags.None);
//Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0 try
if (bytesLeidos == 0 || bytesLeidos == 1) {
bytesLeidos = socket.Receive(bufferSalida, 0, bufferSalida.Length, SocketFlags.None);
}
catch (SocketException ex)
{
if (ex.SocketErrorCode == SocketError.TimedOut)
{
Log.Information("Tiempo de espera agotado. No se recibieron más datos.");
break;
}
}
//Coloque 1 Porque POSBC si no tiene mas bytes que mandar, manda 1 y no 0
if (bytesLeidos == 0 || bytesLeidos == 1)
{ {
// El socket se ha cerrado // El socket se ha cerrado
break; break;
......
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