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 Socket |
getSocket()
get the actual socket
|
void |
initializeConnection()
Actually make the connection and wait for data.
|
static void |
main(String[] args) |
void |
print(String message)
print something to the socket.
|
protected boolean |
processData(String line)
do something with a line of input.
|
String |
readLine()
read a line from the socket
|
void |
run()
The body of the server thread.
|
protected void |
setSocket(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()
.public void initializeConnection()
protected boolean processData(String line)
line
- the inputpublic void print(String message)
message
- the message, if not connected nothing happenspublic String readLine() throws IOException
IOException
protected Socket getSocket()
protected void setSocket(Socket s)
s
- the socketpublic static void main(String[] args)