|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectserver.framework.network.SocketWrapper
public class SocketWrapper
A wrapper class that is used to provide common methods for sending and receiving
messages independent of whether TCP or UDP is used for the message transmission.
Each connected client has a unique SocketWrapper
instance, that is
identified by its remoteAddress
variable.
Constructor Summary | |
---|---|
SocketWrapper(java.lang.Object socket)
Creates a SocketWrapper instance. |
Method Summary | |
---|---|
void |
close()
Closes the connection when this is needed (TCP only) |
boolean |
equals(SocketWrapper other)
Checks whether two SocketWrapper objects are equal. |
java.net.SocketAddress |
getRemoteAddress()
|
java.lang.Object |
getSocket()
|
boolean |
isConnected()
|
java.lang.String |
readMessage(int sleeptime)
Listens for incoming messages. |
void |
sendMessage(java.lang.String message)
Sends a message in the specified format. |
void |
setMessageSize(int messageSize)
Only used when running tests |
void |
setPlayer(AbstractPlayer player)
Sets the player that "owns" this SocketWrapper . |
void |
setRemoteAddress(java.net.SocketAddress remoteAddress)
Sets the address of the associated client. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SocketWrapper(java.lang.Object socket)
SocketWrapper
instance. If the socket parameter
is a Socket
object, this object will use TCP for its communication.
If the socket is a DatagramSocket
, it will use UDP.
socket
- The socket determining what kind of transport protocol to use.Method Detail |
---|
public void setRemoteAddress(java.net.SocketAddress remoteAddress)
remoteAddress
- The address of the associated client.public java.net.SocketAddress getRemoteAddress()
public boolean equals(SocketWrapper other)
SocketWrapper
objects are equal. This method
is used to determine the sender of received messages.
other
- The SocketWrapper
that received the message.
public java.lang.Object getSocket()
public void sendMessage(java.lang.String message)
message
- The message to sendpublic java.lang.String readMessage(int sleeptime)
sleeptime
- How long the tread sleeps between each time it checks the input stream (TCP only).
public boolean isConnected()
public void close()
public void setPlayer(AbstractPlayer player)
SocketWrapper
.
player
- The owner of this object.public void setMessageSize(int messageSize)
messageSize
- The expected size of messages to receive
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |