Exemplo n.º 1
0
 private void threadWait4Clients()
 {
     try
     {
         CLNBTN_Lg objL_Log = new CLNBTN_Lg(_st_User, _st_FileLog, _bl_OutLineConsole, _bl_OutFileLog, _bl_OutWindow);
         objL_Log.WriteTextInLog(_st_Relac + " " + _st_RelacSon + " threadWait4Clients. Beginnig PANDORA Server On TCP Port :  [" + puerto.ToString() + "] ");
         Console.WriteLine("Beginnig PANDORA Server On TCP Port :  [" + puerto.ToString() + "] ");
         ipaddress   = IPAddress.Parse(direccionIP);
         tcplistener = new TcpListener(ipaddress, puerto);
         //tcplistener = new TcpListener(puerto);
         tcplistener.Start();
         //
         while (conectado)
         {
             objL_Log.WriteTextInLog(_st_Relac + " " + _st_RelacSon + " threadWait4Clients. Waiting for Client ...");
             Console.WriteLine("Waiting for Client ...");
             //
             socketCliente = tcplistener.AcceptSocket();
             //
             //Entrando un cliente
             objL_Log.WriteTextInLog(_st_Relac + " " + _st_RelacSon + " threadWait4Clients. Client Connected [" + socketCliente.RemoteEndPoint + "] ");
             Console.WriteLine("Client Connected [" + socketCliente.RemoteEndPoint + "] ");
             int llaveCliente = clientesConectados.Count;
             objL_Log.WriteTextInLog(_st_Relac + " " + _st_RelacSon + " threadWait4Clients. Key for Client [" + llaveCliente.ToString() + "] ");
             Console.WriteLine("Key for Client [" + llaveCliente.ToString() + "] ");
             //CLNBTN_FuncKrl o_cliente = new CLNBTN_FuncKrl(this,socketCliente,(clientesConectados.Count));
             CLNBTN_FuncKrl o_cliente = new CLNBTN_FuncKrl(_st_Lic, _st_User, _st_FileLog, this, socketCliente, (clientesConectados.Count));
             o_cliente.setObjetoParaSalida(this);
             clientesConectados.Add(o_cliente);
             clientesConectados[(clientesConectados.Count - 1)].setTimeout(timeout);
             clientesConectados[(clientesConectados.Count - 1)].start();
             //
         }
     }
     catch (System.AccessViolationException ex_0)
     {
         CLNBTN_Lg objL_Log = new CLNBTN_Lg(_st_User, _st_FileLog, _bl_OutLineConsole, _bl_OutFileLog, _bl_OutWindow);
         objL_Log.WriteOutErrorMessage(_st_Relac, _st_RelacSon, "threadWait4Clients. System.AccessViolationException", "", ex_0.Message.ToString());
     }
     catch (Exception ex)
     {
         CLNBTN_Lg objL_Log = new CLNBTN_Lg(_st_User, _st_FileLog, _bl_OutLineConsole, _bl_OutFileLog, _bl_OutWindow);
         objL_Log.WriteOutErrorMessage(_st_Relac, _st_RelacSon, "threadWait4Clients. Exception", "", ex.Message.ToString());
     }
 }
Exemplo n.º 2
0
        private void nucleoFunciones()
        {
            try
            {
                //Crear buffer de lectura y escritura
                networkStream = new NetworkStream(socketCliente);
                streamWriter  = new StreamWriter(networkStream);
                streamReader  = new StreamReader(networkStream);
                String cadenaEntrada = "";
                //
                CLNBTN_Protocol protocolo = new CLNBTN_Protocol();
                s_ipcliente = socketCliente.RemoteEndPoint.ToString();
                //
                CLNBTN_Lg objL_Log = new CLNBTN_Lg(_st_User, _st_FileLog, _bl_OutLineConsole, _bl_OutFileLog, _bl_OutWindow);
                objL_Log.WriteTextInLog(_st_Relac + " " + _st_RelacSon + " FuncKernel. SRV-PANDORA Index[ " + mi_llave.ToString() + " ] IP[ " + s_ipcliente + " ] ");
                //-->>streamWriter.WriteLine("SRV-PANDORA Index[ "+mi_llave.ToString()+" ] IP[ " +s_ipcliente+ " ] ");
                streamWriter.Flush();
                //
                while (true)
                {
                    cadenaEntrada = streamReader.ReadLine();
                    objL_Log.WriteTextInLog(_st_Relac + " " + _st_RelacSon + " FuncKernel. Input Command From : " + s_ipcliente + " : " + cadenaEntrada);
                    Console.WriteLine("Input Command From : " + s_ipcliente + " : " + cadenaEntrada);
                    protocolo = procesarES(cadenaEntrada);

                    if (protocolo.comando.Contains("SA-SALIR"))
                    {
                        protocolo.respuesta = "SA-SALIR " + mi_llave.ToString();
                        break;
                    }
                    else if (protocolo.comando.Contains("SA-CONSULTA"))
                    {
                        try
                        {
                            if (protocolo.listaparametros.Length > 1)
                            {
                                String cedula = protocolo.listaparametros[0].Trim();

                                String[] datos = new String[1];
                                datos[0] = cedula;
                                ifaz_respuestatcp.x_respuestastcp("SA-CONSULTA", datos);
                                protocolo.respuesta = "SA-CONSULTA " + cedula;
                            }
                            else
                            {
                                protocolo.respuesta = "SA-CONSULTA ERROR " + "Los parametros no son correctos";
                            }
                        }catch (Exception e) {
                            protocolo.respuesta = "SA-CONSULTA ERROR " + e.ToString();
                        }
                    }
                    else if (protocolo.comando.Contains("SA-LOGIN"))
                    {
                        try
                        {
                            if (protocolo.listaparametros.Length > 1)
                            {
                                String usuario = protocolo.listaparametros[0];
                                String clave   = protocolo.listaparametros[1];
                                protocolo.respuesta = "SA-LOGIN " + "90053737892015";
                                String[] datos = new String[3];
                                datos[0] = "90053737892015";
                                datos[1] = usuario;
                                datos[2] = clave;
                                ifaz_respuestatcp.x_respuestastcp("SA-LOGIN", datos);
                            }
                            else
                            {
                                protocolo.respuesta = "SA-LOGIN ERROR " + "Los parametros no son correctos";
                            }
                        }
                        catch (Exception e)
                        {
                            protocolo.respuesta = "SA-LOGIN ERROR " + e.ToString();
                        }
                    }
                    else
                    {
                        protocolo.respuesta = "SRV-PANDORA Terminando Conexion ...";
                    }
                    //Escribiendo la salida
                    if (protocolo.respuesta.Length > 0)
                    {
                        objL_Log.WriteTextInLog(_st_Relac + " " + _st_RelacSon + " FuncKernel. Sending response to : " + s_ipcliente + " : " + protocolo.respuesta);
                        //-->>Console.Write("Enviando respuesta a : " + s_ipcliente + " : " + protocolo.respuesta);
                        streamWriter.WriteLine(protocolo.respuesta);
                        streamWriter.Flush();
                        break;
                    }
                }
                Desconectar();
                servidortcp.Want2Exit(this);
                //
            }
            catch (System.AccessViolationException ex_0)
            {
                CLNBTN_Lg objL_Log = new CLNBTN_Lg(_st_User, _st_FileLog, _bl_OutLineConsole, _bl_OutFileLog, _bl_OutWindow);
                objL_Log.WriteOutErrorMessage(_st_Relac, _st_RelacSon, "nucleoFunciones. System.AccessViolationException", "", ex_0.Message.ToString());
                mensajeError = ex_0.ToString();
            }
            catch (Exception ex)
            {
                CLNBTN_Lg objL_Log = new CLNBTN_Lg(_st_User, _st_FileLog, _bl_OutLineConsole, _bl_OutFileLog, _bl_OutWindow);
                objL_Log.WriteOutErrorMessage(_st_Relac, _st_RelacSon, "nucleoFunciones. Exception", "", ex.Message.ToString());
                mensajeError = ex.ToString();
            }
        }