|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectamip.api.highlevel.Server
public class Server
Server class operates the server on your side. Server is required when you want to receive events and messages from
AMIP. Server opens a socket on the specified address and listens for AMIP connections. This class also provides
access to the EventListenerManager
. Only one instance of Server can be created. To get the Server instance,
use getInstance()
method. Once you have it, you need to start the server. Server must be stopped when you exit
your application.
Method Summary | |
---|---|
static int |
findFreeLocalPort()
The same as findFreePort() , but looks for free port only on the local address. |
static int |
findFreelPort(java.lang.String iface)
Searches for the free port in range on the specified interface. |
static int |
findFreePort()
Helper method to find a free port for the server. |
java.lang.String |
getBindAddress()
|
EventListenerManager |
getEventListenersManager()
Provides access to EventListenerManager useful when you need to receive events from AMIP. |
java.lang.String |
getExternalAddress()
This method returns an external address of the server, which equals to bindAddress by default or null if bindAddress is "0.0.0.0" and externalAddress was not explicitly set. |
static Server |
getInstance()
Gets the Server instance, this is the only way to get the Server object. |
int |
getPort()
|
boolean |
isStarted()
|
void |
setBindAddress(java.lang.String bindAddress)
|
void |
setExternalAddress(java.lang.String externalAddress)
You only need to set it if you start your server on all the addresses available on your machine. |
void |
setPort(int port)
|
void |
start()
Starts the server on 127.0.0.1:60334 or another address and port previously specified by setBindAddress and setPort methods. |
void |
start(java.lang.String bindAddress,
int port)
Starts the server on the specified bindAddress and port. bindAddress must be a valid network address, use 127.0.0.1 to start server on the localhost. |
void |
stop()
Stops the server, you must stop it before your application is terminated. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public void start(java.lang.String bindAddress, int port) throws ServerStartupFailedException
setExternalAddress(java.lang.String)
method, this address is passed to AMIP so that it knows
where it should connect.
bindAddress
- valid IP address of your machine, or 127.0.0.1 if AMIP is on the same machine, or 0.0.0.0 if you
want to listen on all addresses.port
- port to start the server on, use one of the ports which is free or get one using the
findFreePort method.
ServerStartupFailedException
- if server was not started, usually it happens if this port is already taken by
another application or specified IP address is invalid.public void start() throws ServerStartupFailedException
ServerStartupFailedException
- if the server cannot be started (usually when port is already in use or
specified inerface doesn't exist).public void stop()
public static Server getInstance()
Server
instance, this is the only way to get the Server object.
public EventListenerManager getEventListenersManager()
EventListenerManager
useful when you need to receive events from AMIP.
EventListenerManager
instance.public java.lang.String getBindAddress()
public void setBindAddress(java.lang.String bindAddress)
public int getPort()
public void setPort(int port)
public boolean isStarted()
public java.lang.String getExternalAddress()
public void setExternalAddress(java.lang.String externalAddress)
externalAddress
- machine external address.public static int findFreePort()
public static int findFreeLocalPort()
findFreePort()
, but looks for free port only on the local address.
public static int findFreelPort(java.lang.String iface)
iface
- network interface IP address in a string form
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |