|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
eap.freeciv.PacketConnection
Represents a socket connection through which freeciv packets will flow.
The main purpose of this class is to run a thread which listens for packets
from the socket and passes them to registered PacketListener
objects.
Such a connection may be on either the client or server side.
The typical way to use this class is to create a Socket
, use it
to create a PacketConnection, register listeners with
addPacketListener(PacketListener)
, and then call beginListening()
to start the packet listening thread.
Usually, a Client
or Server
will handle much of this for you.
Field Summary |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
PacketConnection(Socket socket)
Create a new connection associated with the given socket. |
Method Summary | |
void |
addPacketListener(PacketListener l)
Register a listener to receive the packets that this class reads from the socket. |
void |
beginListening()
Starts the listening thread. |
void |
run()
This method is required by the Thread class. |
void |
sendPacket(Packet packet)
Send a packet through the socket. |
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 |
Constructor Detail |
public PacketConnection(Socket socket) throws IOException
Method Detail |
public void sendPacket(Packet packet) throws IOException
IOException
public void addPacketListener(PacketListener l)
public void beginListening()
Here's a thought - maybe the thread should wait if there are no listeners registered. The only downside is that the a connection could never just discard packets - but I can't think of a reason you would need it to, and even if you did you could just create a "/dev/null" packet listener.
public void run()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |