org.javagamesfactory.nioservers
Class SimpleServerDemo

java.lang.Object
  extended by org.javagamesfactory.nioservers.StringBasedServer
      extended by org.javagamesfactory.nioservers.SimpleServerDemo
All Implemented Interfaces:
java.lang.Runnable

public class SimpleServerDemo
extends StringBasedServer

This is the class that runs automatically if you run the jar-file as an executable

Starts a simple server, and a simple client, and sends the server a hello-world style message every 5 seconds, while printing a summary of what is happening to std-out


Field Summary
 
Fields inherited from class org.javagamesfactory.nioservers.StringBasedServer
connectedChannels, defaultByteBufferSize, logger, messageLengths, myInfo, pendingOutgoingEncodedMessages, pendingOutgoingMessages, port, readBufferIsEmpty, readByteBuffers, readCharBuffers, selector, status, targetPort, verboseLogger, writeByteBuffers
 
Constructor Summary
SimpleServerDemo(int p)
          Delegates directly to super-constructor with same signature
 
Method Summary
protected  void keyCancelled(java.nio.channels.SelectionKey key)
          Empty method body
static void main(java.lang.String[] args)
          Accepts one optional argument - the port to which the server should bind itself
protected  void postSelect(long millisecondsSinceLastStarted)
          Empty method body
protected  void processStringMessage(java.lang.String message, java.nio.channels.SelectionKey key)
          Simply prints the message to std-out
 
Methods inherited from class org.javagamesfactory.nioservers.StringBasedServer
addErrorToKey, addMessageToKey, debug, debugVerbose, error, error, getNumberOfConnectedChannels, getPort, getStatus, info, info, infoVerbose, peekOutgoingMessageQueueForKey, readIncomingMessageFromKey, run, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleServerDemo

public SimpleServerDemo(int p)
                 throws java.net.UnknownHostException
Delegates directly to super-constructor with same signature

Parameters:
p -
Throws:
java.net.UnknownHostException
Method Detail

keyCancelled

protected void keyCancelled(java.nio.channels.SelectionKey key)
Empty method body

Specified by:
keyCancelled in class StringBasedServer

postSelect

protected void postSelect(long millisecondsSinceLastStarted)
Empty method body

Specified by:
postSelect in class StringBasedServer
Parameters:
millisecondsSinceLastStarted - the number of milliseconds since this method was last called; i.e. the time at which it was INVOKED, not the time at which it RETURNED; this is perfect for maintaining fixed-rate game loops

processStringMessage

protected void processStringMessage(java.lang.String message,
                                    java.nio.channels.SelectionKey key)
                             throws java.nio.channels.ClosedChannelException
Simply prints the message to std-out

Specified by:
processStringMessage in class StringBasedServer
Throws:
java.nio.channels.ClosedChannelException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Throwable
Accepts one optional argument - the port to which the server should bind itself

Parameters:
args -
Throws:
java.lang.Throwable