public class TCPServer
extends java.lang.Object
implements java.lang.Runnable, java.lang.Cloneable
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PORT |
Constructor and Description |
---|
TCPServer()
default constructor.
|
TCPServer(int port)
Create a ServerSocket to listen for connections on If port < 0 or port >
65535 port defaults to DEFAULT_PORT.
|
Modifier and Type | Method and Description |
---|---|
protected java.net.Socket |
getSocket()
get the actual socket
|
void |
initializeConnection()
Actually make the connection and wait for data.
|
static void |
main(java.lang.String[] args) |
void |
print(java.lang.String message)
print something to the socket.
|
protected boolean |
processData(java.lang.String line)
do something with a line of input.
|
java.lang.String |
readLine()
read a line from the socket
|
void |
run()
The body of the server thread.
|
protected void |
setSocket(java.net.Socket s)
set the actual socket.
|
public static final int DEFAULT_PORT
public TCPServer()
public TCPServer(int port)
port
- the port to listen onpublic void run()
initializeConnection()
.run
in interface java.lang.Runnable
public void initializeConnection()
protected boolean processData(java.lang.String line)
line
- the inputpublic void print(java.lang.String message)
message
- the message, if not connected nothing happenspublic java.lang.String readLine() throws java.io.IOException
java.io.IOException
protected java.net.Socket getSocket()
protected void setSocket(java.net.Socket s)
s
- the socketpublic static void main(java.lang.String[] args)