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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTCPNetworkClientManager(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 TypeMethodDescriptionvoidaddMessage(Message msg)This method add a message to be delivered to the client the message is pointed to.voidfinish()This method notify the thread to finish it executionReturns the ip address and port-numberbooleanReturns 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.voidretrieveMessages(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:INetworkClientManagerInterfaceThis method notify the thread to finish it execution- Specified by:
finishin interfaceINetworkClientManagerInterface
-
getAddress
Description copied from interface:INetworkClientManagerInterfaceReturns the ip address and port-number- Specified by:
getAddressin interfaceINetworkClientManagerInterface- Returns:
- InetSocketAddress
-
getMessage
Description copied from interface:INetworkClientManagerInterfaceThis method returns a Message from the list or block for timeout milliseconds until a message is available or null if timeout happens.- Specified by:
getMessagein 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:INetworkClientManagerInterfaceThis method add a message to be delivered to the client the message is pointed to.- Specified by:
addMessagein 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:
getConnectionStatein interfaceINetworkClientManagerInterface- Returns:
- true if socket is connected.
-