{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Servidor(1) - Configurar un servidor que reciba una conexin...

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// Configurar un servidor que reciba una conexi n de un cliente, env e // una cadena al cliente y cierre la conexi n. import java.io.*; import java.net.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Servidor extends JFrame { private JTextField campoIntroducir; private JTextArea areaPantalla; private ObjectOutputStream salida; private ObjectInputStream entrada; private ServerSocket servidor; private Socket conexion; private int contador = 1; // configurar GUI public Servidor() { super( "Servidor" ); Container contenedor = getContentPane(); // crear campoIntroducir y registrar componente de escucha campoIntroducir = new JTextField(); campoIntroducir.setEditable( false ); campoIntroducir.addActionListener( new ActionListener() { // enviar mensaje al cliente public void actionPerformed( ActionEvent evento ) { enviarDatos( evento.getActionCommand() ); campoIntroducir.setText( "" ); } } ); contenedor.add( campoIntroducir, BorderLayout.NORTH ); // crear areaPantalla areaPantalla = new JTextArea(); contenedor.add( new JScrollPane( areaPantalla ), BorderLayout.CENTER ); setSize( 300, 150 ); setVisible( true ); } // fin del constructor de Servidor // configurar y ejecutar el servidor public void ejecutarServidor() { // configurar servidor para que reciba conexiones; procesar las conexiones try { // Paso 1: crear un objeto ServerSocket.
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern