org.starhope.vergil.net
Interface ServerConnection

All Known Implementing Classes:
WebSocketServerConnection

public interface ServerConnection

Generic interface for some kind of connection to the server, must provide only the most basic functionality.

Author:
brpocock@star-hope.org

Method Summary
 void connect(String newHost, int port, String newZone)
          Connect to a game server
 void disconnect()
          Disconnect.
 String getHost()
           
 int getPort()
           
 String getZone()
           
 com.google.gwt.json.client.JSONValue readMessage()
          Retrieve the next message from the server's queue, or null if there are no messages waiting
 com.google.gwt.json.client.JSONObject readMessageBlocking()
          Retrieves the next message from the server, blocking to wait for one if there are none queued.
 void sendMessage(com.google.gwt.json.client.JSONObject jso)
          Send a message to the server
 

Method Detail

connect

void connect(String newHost,
             int port,
             String newZone)
             throws IOException,
                    ServerDisconnectedException
Connect to a game server

Parameters:
newHost - host name or IP address (in whatever notation the local networking code understands)
port - TCP (or UDP…?) port number
newZone - the zone on that port, to which to connect ($Eden is login zone)
Throws:
IOException - if some kind of problem prevents a connection; subclasses might make sense to the local code, to be able to provide better diagnostic information for the end-user
ServerDisconnectedException - if the connection is lost (but was basically established)

disconnect

void disconnect()
Disconnect.


getHost

String getHost()
Returns:
the host address or name; or null, if not connected

getPort

int getPort()
Returns:
the host TCP (or UDP…) port number. -1 can be returned for either not-connected or not-applicable (e.g. using some kind of RPC mechanism)

getZone

String getZone()
Returns:
the current Zone, or null, if not connected

readMessage

com.google.gwt.json.client.JSONValue readMessage()
                                                 throws ServerDisconnectedException
Retrieve the next message from the server's queue, or null if there are no messages waiting

Returns:
the next message from the server, or null if there are none pending
Throws:
ServerDisconnectedException - if the connection is lost

readMessageBlocking

com.google.gwt.json.client.JSONObject readMessageBlocking()
                                                          throws ServerDisconnectedException
Retrieves the next message from the server, blocking to wait for one if there are none queued.

Returns:
the next message from the server
Throws:
ServerDisconnectedException - if the connection is lost

sendMessage

void sendMessage(com.google.gwt.json.client.JSONObject jso)
                 throws ServerDisconnectedException
Send a message to the server

Parameters:
jso - JSON data
Throws:
ServerDisconnectedException - if the connection is lost