triptracker.core
Class Protocol

java.lang.Object
  extended by triptracker.core.Protocol

public class Protocol
extends Object

The Protocol class works by being a common place where both the server and client can obtain information in order to conform to the protocol.


Field Summary
static int AUTH_FAIL
          Authentication failed.
static int AUTH_OK
          Authentication successful.
static int COORD_ADD
          New coordinate added.
static int COORD_BUFFER_ADD
          Add a bundle of coordinates.
static String DELIMITER
          Message field delimiter.
static String HOST
          Default host address.
static int MAKE_ROUTE
          Make a new route.
static int MAPCLIENT
          Client is a coordinate reciever/sink.
static String NEWLINE
          The newline character separating each message.
static int PORTNR
          Default protocol port number.
static int QUIT
          Client wants to terminate the connection.
static int REALTIME
          Realtime state has changed.
static int ROUTE_GET
          Get all coodinates for spesific route.
static int ROUTE_LOCK
          Lock/unlock a route.
static int SENDCLIENT
          Client is a coordinate sender/source.
static int SET_ROUTE
          Set active route.
static int USER_GET
          Gets spesific user
static int USERS_GET
          Get list of all users.
static int VIEW_ROUTES
          Request for a list of all routes for a spesific user.
static int ZIP_BUFFERSIZE
          Default compressed buffersize.
 
Constructor Summary
Protocol()
           
 
Method Summary
static String makeMsg(Object... message)
          Builds a message by adding DELIMITER between each message part and putting NEWLINE at the end.
static StringBuilder makeMsg(StringBuilder builder, Object... message)
          Builds a message by adding DELIMITER between each message part and putting NEWLINE at the end.
static StringBuilder makeMsg(String msgDelim, StringBuilder builder, Object... message)
          Builds a message by adding DELIMITER between each message part and putting msgDelim at the end.
static void send(OutputStream out, boolean flush, Object... message)
          Send a message with the specified stream.
static void send(OutputStream out, Object... message)
          Sends a message with the specified stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEWLINE

public static final String NEWLINE
The newline character separating each message. This is defined to keep the protocol portable and consistent between platforms and languages because the newline used by println() in Java is different on both Windows, Linux/Unix and Mac. Although readLine() in Java automatically handles all newline types, other languages probably won't.

See Also:
Constant Field Values

DELIMITER

public static final String DELIMITER
Message field delimiter.

See Also:
Constant Field Values

PORTNR

public static final int PORTNR
Default protocol port number.

See Also:
Constant Field Values

HOST

public static final String HOST
Default host address.

See Also:
Constant Field Values

ZIP_BUFFERSIZE

public static final int ZIP_BUFFERSIZE
Default compressed buffersize.

See Also:
Constant Field Values

SENDCLIENT

public static final int SENDCLIENT
Client is a coordinate sender/source.

See Also:
Constant Field Values

MAPCLIENT

public static final int MAPCLIENT
Client is a coordinate reciever/sink.

See Also:
Constant Field Values

QUIT

public static final int QUIT
Client wants to terminate the connection.

See Also:
Constant Field Values

AUTH_FAIL

public static final int AUTH_FAIL
Authentication failed.

See Also:
Constant Field Values

AUTH_OK

public static final int AUTH_OK
Authentication successful.

See Also:
Constant Field Values

COORD_ADD

public static final int COORD_ADD
New coordinate added.

Syntax: <latitude>, <longitude>, <dateTime>

The format of dateTime is "yyyy-MM-dd hh:mm:ss".

See Also:
Constant Field Values

COORD_BUFFER_ADD

public static final int COORD_BUFFER_ADD
Add a bundle of coordinates.

Syntax: <zipped string of coordinates>

See Also:
Constant Field Values

MAKE_ROUTE

public static final int MAKE_ROUTE
Make a new route. Also used when returning the route ID to a GPS client after the route is successfully created.

Syntax: <description>

See Also:
Constant Field Values

SET_ROUTE

public static final int SET_ROUTE
Set active route.

Syntax: <routeId>

See Also:
Constant Field Values

VIEW_ROUTES

public static final int VIEW_ROUTES
Request for a list of all routes for a spesific user.

Syntax: <username>

See Also:
Constant Field Values

USERS_GET

public static final int USERS_GET
Get list of all users.

See Also:
Constant Field Values

ROUTE_GET

public static final int ROUTE_GET
Get all coodinates for spesific route.

Syntax: <routeId>

See Also:
Constant Field Values

ROUTE_LOCK

public static final int ROUTE_LOCK
Lock/unlock a route.

Syntax: <routeId>

See Also:
Constant Field Values

REALTIME

public static final int REALTIME
Realtime state has changed. Also used to request a list of realtime routes from the server.

Syntax: <enabled>

enabled: true if realtime is starting, and false if realtime stopped

See Also:
Constant Field Values

USER_GET

public static final int USER_GET
Gets spesific user

See Also:
Constant Field Values
Constructor Detail

Protocol

public Protocol()
Method Detail

send

public static void send(OutputStream out,
                        boolean flush,
                        Object... message)
                 throws IOException
Send a message with the specified stream. The sent message will be composed of the message parts (elements in the message parameter array) separated by the DELIMITER character and the whole message will be terminated by the NEWLINE string.

Parameters:
out - output stream to sent message to
flush - if true flush the output stream and force any buffered output bytes to be written out after the message has been written to the stream
message - message to send
Throws:
IOException - on failed send

send

public static void send(OutputStream out,
                        Object... message)
                 throws IOException
Sends a message with the specified stream. This method has the same effect as send(stream, false, message).

Parameters:
out - output stream to sent message to
message - message to send
Throws:
IOException - on failed send
See Also:
send(OutputStream, boolean, Object[])

makeMsg

public static String makeMsg(Object... message)
Builds a message by adding DELIMITER between each message part and putting NEWLINE at the end.

Parameters:
message - parts to delimit
Returns:
properly delimited message
See Also:
makeMsg(String, StringBuilder, Object[])

makeMsg

public static StringBuilder makeMsg(String msgDelim,
                                    StringBuilder builder,
                                    Object... message)
Builds a message by adding DELIMITER between each message part and putting msgDelim at the end. All messages will be appended to the existing builder, or if builder is null then a new StringBuilder will be created.

Parameters:
msgDelim - string to put at the end of the message
builder - StringBuilder to use for adding data, if null then a new string builder will be created
message - parts to delimit
Returns:
StringBuilder containing a properly delimited message including the trailing NEWLINE.

makeMsg

public static StringBuilder makeMsg(StringBuilder builder,
                                    Object... message)
Builds a message by adding DELIMITER between each message part and putting NEWLINE at the end. All messages will be appended to the existing builder, or if builder is null then a new StringBuilder will be created.

Parameters:
builder - StringBuilder to use for adding data, if null then a new string builder will be created
message - parts to delimit
Returns:
StringBuilder containing a properly delimited message including the trailing NEWLINE.


Copyright © 2006 Team Trip Tracker. All Rights Reserved.