Skip to content

Instantly share code, notes, and snippets.

@kurotori
Created September 16, 2024 16:41
Show Gist options
  • Save kurotori/15434cf4918ffa2f3b0992041a37196b to your computer and use it in GitHub Desktop.
Save kurotori/15434cf4918ffa2f3b0992041a37196b to your computer and use it in GitHub Desktop.
Cliente-Servidor Bàsicos en Java
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