commandNetworking
Class Server

java.lang.Object
  extended by commandNetworking.Communicator
      extended by commandNetworking.Server
Direct Known Subclasses:
Main

public class Server
extends Communicator

Server class. May connecto to several clients. Extends the communicator class


Field Summary
protected  boolean[] clientSocketsOpen
          list of open clients. every bool is true only if corresponding client is open
protected  boolean[] hasSentPing
          true if ping is sent corresponding client
protected  boolean isAllSocketsOpen
          true only if all clients is connected
protected  int pingErrorCounter
          counts the number of ping errors.
protected  int[] ports
          lists of ports, sockets, sender objects and client sockets
 
Constructor Summary
Server(int[] ports)
          Sets up a server waiting to connect on given ports
 
Method Summary
 void Listen()
          Start listening from clients
 void ProcessCommand(Packet pck)
          Process ping packets only.
 void Talk(Packet pck)
          Sends a message from the communicator Empty method to ensure it can be called, but all communicators may overwrite this method
 void Talk(Packet command, int index)
          Sends a packet to a given client
 void UpdateStatus(int index)
          Update connection status of the server
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ports

protected int[] ports
lists of ports, sockets, sender objects and client sockets


isAllSocketsOpen

protected boolean isAllSocketsOpen
true only if all clients is connected


pingErrorCounter

protected int pingErrorCounter
counts the number of ping errors. Resets when a correct ping is received. Status is unconnected if three pings fail


clientSocketsOpen

protected boolean[] clientSocketsOpen
list of open clients. every bool is true only if corresponding client is open


hasSentPing

protected boolean[] hasSentPing
true if ping is sent corresponding client

Constructor Detail

Server

public Server(int[] ports)
Sets up a server waiting to connect on given ports

Parameters:
ports -
Method Detail

ProcessCommand

public void ProcessCommand(Packet pck)
Process ping packets only. To use other packets, classes can overwrite this method

Parameters:
pck -

Talk

public void Talk(Packet pck)
Description copied from class: Communicator
Sends a message from the communicator Empty method to ensure it can be called, but all communicators may overwrite this method

Overrides:
Talk in class Communicator

Talk

public void Talk(Packet command,
                 int index)
Sends a packet to a given client

Parameters:
command -
index -

Listen

public void Listen()
Start listening from clients


UpdateStatus

public void UpdateStatus(int index)
Update connection status of the server

Parameters:
index -