Diploma

Páginas: 2 (366 palabras) Publicado: 29 de noviembre de 2012
import java.net.*;
import java.io.*;

public class NakovChatServer
{
public static final int LISTENING_PORT = 2002;

public static void main(String[] args)
{
// Open server socket forlistening
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(LISTENING_PORT);
System.out.println("NakovChatServer started on port " + LISTENING_PORT);
} catch(IOException se) {
System.err.println("Can not start listening on port " + LISTENING_PORT);
se.printStackTrace();
System.exit(-1);
}

// Start ServerDispatcher threadServerDispatcher serverDispatcher = new ServerDispatcher();
serverDispatcher.start();

// Accept and handle client connections
while (true) {
try {
Socket socket = serverSocket.accept();ClientInfo clientInfo = new ClientInfo();
clientInfo.mSocket = socket;
ClientListener clientListener =
new ClientListener(clientInfo, serverDispatcher);
ClientSender clientSender =new ClientSender(clientInfo, serverDispatcher);
clientInfo.mClientListener = clientListener;
clientInfo.mClientSender = clientSender;
clientListener.start();clientSender.start();
serverDispatcher.addClient(clientInfo);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}

}


/**
* Nakov Chat Server
* (c) Svetlin Nakov, 2002
*
*ServerDispatcher class is purposed to listen for messages received
* from clients and to dispatch them to all the clients connected to the
* chat server.
*/

import java.net.*;
import java.util.*;public class ServerDispatcher extends Thread
{
private Vector mMessageQueue = new Vector();
private Vector mClients = new Vector();

/**
* Adds given client to the server's client list.
*/public synchronized void addClient(ClientInfo aClientInfo)
{
mClients.add(aClientInfo);
}

/**
* Deletes given client from the server's client list
* if the client is in the list....
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Diploma
  • Diplomado
  • Diplomado
  • Diplomado
  • Diploma
  • Diplomado
  • Diplomado
  • Diplomado

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS