Package marauroa.client.net
Class TCPNetworkClientManager
java.lang.Object
marauroa.client.net.TCPNetworkClientManager
- All Implemented Interfaces:
INetworkClientManagerInterface
This is the basic implementation of a TCP network manager.
- Author:
- hendrik
-
Field Summary
-
Constructor Summary
ConstructorDescriptionTCPNetworkClientManager(String host, int port)
Constructor that opens the socket on the marauroa_PORT and start the thread to receive new messages from the network.TCPNetworkClientManager(Proxy proxy, InetSocketAddress serverAddress)
Constructor that opens the socket on the marauroa_PORT and start the thread to receive new messages from the network. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMessage(Message msg)
This method add a message to be delivered to the client the message is pointed to.void
finish()
This method notify the thread to finish it executionReturns the ip address and port-numberboolean
Returns true if the connection is "connected" to server or false otherwise.getMessage(int timeout)
This method returns a Message from the list or block for timeout milliseconds until a message is available or null if timeout happens.Deprecated.void
retrieveMessages(Collection<? super Message> drainTo)
gets all messages received so far and removes them from the queue.
-
Field Details
-
registered
protected static boolean registeredalready registered?
-
-
Constructor Details
-
TCPNetworkClientManager
Constructor that opens the socket on the marauroa_PORT and start the thread to receive new messages from the network.- Parameters:
host
- the host where we connect to.port
- the port of the server where we connect to.- Throws:
IOException
-
TCPNetworkClientManager
Constructor that opens the socket on the marauroa_PORT and start the thread to receive new messages from the network.- Parameters:
proxy
- proxy server and protocol to useserverAddress
- the host and port where we connect to.- Throws:
IOException
-
-
Method Details
-
finish
public void finish()Description copied from interface:INetworkClientManagerInterface
This method notify the thread to finish it execution- Specified by:
finish
in interfaceINetworkClientManagerInterface
-
getAddress
Description copied from interface:INetworkClientManagerInterface
Returns the ip address and port-number- Specified by:
getAddress
in interfaceINetworkClientManagerInterface
- Returns:
- InetSocketAddress
-
getMessage
Description copied from interface:INetworkClientManagerInterface
This method returns a Message from the list or block for timeout milliseconds until a message is available or null if timeout happens.- Specified by:
getMessage
in interfaceINetworkClientManagerInterface
- Parameters:
timeout
- timeout time in milliseconds- Returns:
- a Message or null if timeout happens
- Throws:
InvalidVersionException
-
retrieveMessages
gets all messages received so far and removes them from the queue.- Parameters:
drainTo
- the messages received
-
getMessages
Deprecated.gets all messages received so far and removes them from the queue.- Returns:
- the messages received
-
addMessage
Description copied from interface:INetworkClientManagerInterface
This method add a message to be delivered to the client the message is pointed to.- Specified by:
addMessage
in interfaceINetworkClientManagerInterface
- Parameters:
msg
- the message to be delivered.
-
getConnectionState
public boolean getConnectionState()Returns true if the connection is "connected" to server or false otherwise.- Specified by:
getConnectionState
in interfaceINetworkClientManagerInterface
- Returns:
- true if socket is connected.
-