public class Connection
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.io.ObjectInputStream |
in
The input stream for this connection.
|
private java.io.ObjectOutputStream |
out
The output stream for this connection.
|
private java.net.Socket |
socket
The socket for this connection.
|
Modifier | Constructor and Description |
---|---|
protected |
Connection(java.net.Socket socket)
Constructs a new connection from the given socket.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this connection.
|
boolean |
isClosed()
Checks if this connection is closed.
|
Packet |
readPacket()
Reads a new packet from the connection.
|
void |
sendPacket(Packet packet)
Sends a new packet over this connection.
|
private java.io.ObjectInputStream in
private java.io.ObjectOutputStream out
private java.net.Socket socket
protected Connection(java.net.Socket socket) throws java.io.IOException
socket
- The socket for the connection.java.io.IOException
- When some IOException occurs.public Packet readPacket() throws java.io.IOException
null
when something unexpected happened or
the connection is closed.java.io.IOException
- When some IOException occurs.public void sendPacket(Packet packet) throws java.io.IOException
packet
- The packet to send.java.io.IOException
- When some IOException occurs.public boolean isClosed()
public void close()