Created
September 16, 2024 16:41
-
-
Save kurotori/15434cf4918ffa2f3b0992041a37196b to your computer and use it in GitHub Desktop.
Cliente-Servidor Bàsicos en Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package red; | |
import java.net.*; | |
import java.io.*; | |
public class Servidor { | |
private Socket conexionCliente; | |
private ServerSocket conexionServidor; | |
private PrintWriter salida; | |
private BufferedReader entrada; | |
public void iniciar(int puerto){ | |
try { | |
System.out.println("Iniciando..."); | |
conexionServidor = new ServerSocket(puerto); | |
conexionCliente = conexionServidor.accept(); | |
System.out.println("Cliente conectado:"+ | |
conexionCliente.getInetAddress() | |
.getCanonicalHostName()); | |
InputStreamReader lector = | |
new InputStreamReader( | |
conexionCliente. | |
getInputStream() | |
); | |
entrada = new BufferedReader(lector); | |
salida = new PrintWriter( | |
conexionCliente.getOutputStream(), | |
true); | |
} catch (Exception error) { | |
System.out.println("ERROR: " + error.getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment