com.joctopus.server
Class Server

java.lang.Object
  extended by java.lang.Thread
      extended by com.joctopus.server.Server
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
FileRecieverServer, FileTransferServer

public class Server
extends java.lang.Thread

Represents background service, for listening binary file transfers or simple text transfers.The server is multithreaded for background working, and for providing good performance.

Since:
1.0

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 boolean debug
          if true then output will be written in console window.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Server(int port, JOctopusConsole chatterConsole)
           
Server(int port, java.lang.ThreadGroup group, JOctopusConsole chatterConsole)
           
Server(JOctopusConsole chatterConsole)
           
 
Method Summary
 void addMessageRecieveListener(MessageRecieveListener messageRecieveListener)
          sets message recieve listener, its recieveMessage() will be called on recieving client notification.
 java.net.ServerSocket getChatServerSocket()
          Returns ServerSocket Object
 JOctopusConsole getChatterConsole()
           
 MessageRecieveListener getMessageRecieveListener()
          returns messageRecievelistener object.
 int getPort()
          returns port at which the server is bind and listening for client.
 java.net.Socket getRecievedClientSocket()
          returns Socket Object that have been recieved, after notification.
 java.nio.channels.SocketChannel getRecievedClientSocketChannel()
          Returns SocketChannelObject that have been recieved while listening to the port.
 java.lang.String getServerName()
          returns name of server
 java.nio.channels.ServerSocketChannel getServerSocketChannel()
          Returns ServerSocketChannel Object that has been listening for client.
protected  void instantiateServer()
          Instantiates server running for recieving txt messages, else instantiates server socket channel object when server is running for recieving files i.e for File Transfer
 boolean isFailToRun()
          returns true if some error has occurred in server else false.
 boolean isStarted()
           
 void run()
           
 void setPort(int port)
          Sets port.This method should be called before StartServer()
protected  void setRecievedClientSocket(java.net.Socket recievedClientSocket)
          sets recieved client socket.
 void setServerName(java.lang.String serverName)
          Sets server name.
 void startServer()
          starts server.
 void stopService()
          Stops the service.
 void writeOut(java.lang.String message)
          writes output to JOctopusConsole window
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

debug

public boolean debug
if true then output will be written in console window.

Constructor Detail

Server

public Server(JOctopusConsole chatterConsole)
Parameters:
chatterConsole -

Server

public Server(int port,
              JOctopusConsole chatterConsole)
Parameters:
port -
chatterConsole -

Server

public Server(int port,
              java.lang.ThreadGroup group,
              JOctopusConsole chatterConsole)
Parameters:
port -
group -
chatterConsole -
Method Detail

getChatterConsole

public JOctopusConsole getChatterConsole()
Returns:
chatter console object.

isFailToRun

public boolean isFailToRun()
returns true if some error has occurred in server else false.

Returns:
the failToRun

getRecievedClientSocketChannel

public java.nio.channels.SocketChannel getRecievedClientSocketChannel()
Returns SocketChannelObject that have been recieved while listening to the port.

Returns:
socketchannel

setRecievedClientSocket

protected void setRecievedClientSocket(java.net.Socket recievedClientSocket)
sets recieved client socket.

Parameters:
recievedClientSocket -

getServerSocketChannel

public java.nio.channels.ServerSocketChannel getServerSocketChannel()
Returns ServerSocketChannel Object that has been listening for client.

Returns:
ServerSocketChannel

getChatServerSocket

public java.net.ServerSocket getChatServerSocket()
Returns ServerSocket Object

Returns:
ServerSocket

getServerName

public java.lang.String getServerName()
returns name of server

Returns:
ServerName

setServerName

public void setServerName(java.lang.String serverName)
Sets server name.

Parameters:
serverName -

getPort

public int getPort()
returns port at which the server is bind and listening for client.

Returns:
Port

setPort

public void setPort(int port)
Sets port.This method should be called before StartServer()

Parameters:
port -

getRecievedClientSocket

public java.net.Socket getRecievedClientSocket()
returns Socket Object that have been recieved, after notification. Socket object describes the client, that invoked server.

Returns:
RecievedClientSocket

getMessageRecieveListener

public MessageRecieveListener getMessageRecieveListener()
returns messageRecievelistener object.

Returns:
MessageRecieveListener

addMessageRecieveListener

public void addMessageRecieveListener(MessageRecieveListener messageRecieveListener)
sets message recieve listener, its recieveMessage() will be called on recieving client notification.

Parameters:
messageRecieveListener -

stopService

public void stopService()
                 throws java.io.IOException
Stops the service.

Throws:
java.io.IOException

isStarted

public boolean isStarted()
Returns:
wheather the server startFlag is true or false

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

instantiateServer

protected void instantiateServer()
                          throws java.net.BindException
Instantiates server running for recieving txt messages, else instantiates server socket channel object when server is running for recieving files i.e for File Transfer

Throws:
java.net.BindException

writeOut

public void writeOut(java.lang.String message)
writes output to JOctopusConsole window

Parameters:
message -

startServer

public void startServer()
                 throws java.net.BindException
starts server.

Throws:
java.net.BindException