com.lukasfeiler.tcpserver
Class TCPSocket

java.lang.Object
  extended byjava.lang.Thread
      extended bycom.lukasfeiler.tcpserver.TCPSocket
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
HTTPSocket

public class TCPSocket
extends java.lang.Thread


Field Summary
protected  java.io.InputStream in
           
protected  java.io.OutputStream out
           
protected  TCPServer server
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected TCPSocket(java.net.Socket s, java.lang.Integer socketId, TCPServer server, int connectionTimeout)
          Creates a new instance of TCPSocket.
 
Method Summary
 void close()
           
 java.lang.String getFullName()
          Returns a String that contains all relavant information about this socket.
 java.lang.String getIP()
          Returns the Internet Protocol Address of the client this socket serves.
 java.lang.String getLocalIP()
          Returns the Internet Protocol Address this client connected to.
 java.lang.String getLocalPort()
          Returns the port number this client connected to.
 java.io.OutputStream getOut()
           
 java.lang.String getPort()
          Returns the port number of the client this socket serves.
 TCPServer getServer()
          Returns the TCPServer object that is connected to this socket.
 java.lang.Integer getSocketId()
          Returns the ID of this socket.
 long getStartTimeInMillis()
           
 void print(java.lang.String s)
           
 void println(java.lang.String s)
          Sends the String to the output PrintWriter connected to this socket.
protected  boolean processInput()
          Processes the input and returns false if the socket is to be closed.
 java.lang.String readLine()
           
 void remove()
           
 void run()
          Starts everything off.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, 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

in

protected java.io.InputStream in

server

protected TCPServer server

out

protected java.io.OutputStream out
Constructor Detail

TCPSocket

protected TCPSocket(java.net.Socket s,
                    java.lang.Integer socketId,
                    TCPServer server,
                    int connectionTimeout)
             throws java.io.IOException
Creates a new instance of TCPSocket.

Parameters:
s - An instance of TCPSocket.
socketId - The ID of this TCPSocket.
Method Detail

getStartTimeInMillis

public long getStartTimeInMillis()

getFullName

public java.lang.String getFullName()
Returns a String that contains all relavant information about this socket.

Returns:
a String in the following format IDsocketId: [clientIP:clientPort connected to localIP:localPort]

println

public void println(java.lang.String s)
             throws java.io.IOException
Sends the String to the output PrintWriter connected to this socket.

Parameters:
s - the String to send.
Returns:
nothing
Throws:
java.io.IOException

print

public void print(java.lang.String s)
           throws java.io.IOException
Throws:
java.io.IOException

readLine

public java.lang.String readLine()
                          throws java.io.IOException,
                                 TCPSocketEndOfStreamException
Throws:
java.io.IOException
TCPSocketEndOfStreamException

getIP

public java.lang.String getIP()
Returns the Internet Protocol Address of the client this socket serves.

Returns:
A String containing the client's IP-Address.

getPort

public java.lang.String getPort()
Returns the port number of the client this socket serves.

Returns:
A String containing the client's port number.

getLocalIP

public java.lang.String getLocalIP()
Returns the Internet Protocol Address this client connected to.

Returns:
A String containing the IP-Address this client connected to.

getLocalPort

public java.lang.String getLocalPort()
Returns the port number this client connected to.

Returns:
A String containing the IP-Address this client connected to.

getServer

public TCPServer getServer()
Returns the TCPServer object that is connected to this socket.

Returns:
The TCPServer object that is connected to this socket.

getSocketId

public java.lang.Integer getSocketId()
Returns the ID of this socket. IDs are starting a 0 and get incremented for each new TCPSocket.

Returns:
An int representing the ID of this socket.

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

remove

public void remove()

run

public void run()
Starts everything off.


processInput

protected boolean processInput()
                        throws java.io.IOException,
                               TCPSocketEndOfStreamException
Processes the input and returns false if the socket is to be closed.

Throws:
java.io.IOException
TCPSocketEndOfStreamException

getOut

public java.io.OutputStream getOut()