org.starhope.vergil.net
Class WebSocketServerConnection

java.lang.Object
  extended by org.starhope.vergil.net.WebSocketServerConnection
All Implemented Interfaces:
ServerConnection

public class WebSocketServerConnection
extends Object
implements ServerConnection

implementation of ServerConnection using WebSocket

Author:
brpocock@star-hope.org

Field Summary
private  String host
          WRITEME: Document this brpocock@star-hope.org
private  int port
          WRITEME: Document this brpocock@star-hope.org
private  WebSocket socket
          The WebSocket connection
private  String zone
          WRITEME: Document this brpocock@star-hope.org
 
Constructor Summary
WebSocketServerConnection()
           
 
Method Summary
 void connect(String newHost, int newPort, String newZone)
          Connect to a game server
 void disconnect()
          Disconnect.
 String getHost()
           
 int getPort()
           
 String getZone()
           
 com.google.gwt.json.client.JSONObject 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

socket

private WebSocket socket
The WebSocket connection


host

private String host
WRITEME: Document this brpocock@star-hope.org


port

private int port
WRITEME: Document this brpocock@star-hope.org


zone

private String zone
WRITEME: Document this brpocock@star-hope.org

Constructor Detail

WebSocketServerConnection

public WebSocketServerConnection()
Method Detail

connect

public void connect(String newHost,
                    int newPort,
                    String newZone)
             throws IOException,
                    ServerDisconnectedException
Description copied from interface: ServerConnection
Connect to a game server

Specified by:
connect in interface ServerConnection
Parameters:
newHost - host name or IP address (in whatever notation the local networking code understands)
newPort - 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)
See Also:
ServerConnection.connect(java.lang.String, int, java.lang.String)

disconnect

public void disconnect()
Description copied from interface: ServerConnection
Disconnect.

Specified by:
disconnect in interface ServerConnection
See Also:
ServerConnection.disconnect()

getHost

public String getHost()
Specified by:
getHost in interface ServerConnection
Returns:
the host address or name; or null, if not connected
See Also:
ServerConnection.getHost()

getPort

public int getPort()
Specified by:
getPort in interface ServerConnection
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)
See Also:
ServerConnection.getPort()

getZone

public String getZone()
Specified by:
getZone in interface ServerConnection
Returns:
the current Zone, or null, if not connected
See Also:
ServerConnection.getZone()

readMessage

public com.google.gwt.json.client.JSONObject readMessage()
                                                  throws ServerDisconnectedException
Description copied from interface: ServerConnection
Retrieve the next message from the server's queue, or null if there are no messages waiting

Specified by:
readMessage in interface ServerConnection
Returns:
the next message from the server, or null if there are none pending
Throws:
ServerDisconnectedException - if the connection is lost
See Also:
TODO: is this blocking? I forget.

readMessageBlocking

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

Specified by:
readMessageBlocking in interface ServerConnection
Returns:
the next message from the server
Throws:
ServerDisconnectedException - if the connection is lost
See Also:
ServerConnection.readMessageBlocking()

sendMessage

public void sendMessage(com.google.gwt.json.client.JSONObject jso)
                 throws ServerDisconnectedException
Description copied from interface: ServerConnection
Send a message to the server

Specified by:
sendMessage in interface ServerConnection
Parameters:
jso - JSON data
Throws:
ServerDisconnectedException - if the connection is lost
See Also:
ServerConnection.sendMessage(com.google.gwt.json.client.JSONObject)