org.hprog.code
Class CodeProtocol

java.lang.Object
  |
  +--org.hprog.code.CodeProtocol

public class CodeProtocol
extends java.lang.Object

A TCP connection to a client or server. The protocol used, in either direction, consists of sequences of bytes indicating commands, followed by additional arguments of numbers and types specific to each command. The arguments are sent with ObjectInputStreams and ObjectOutputStreams.


Nested Class Summary
 class CodeProtocol.Exn
          Exception for network errors.
 
Field Summary
 boolean admin
          Is this a client-to-server connection belonging to an operator?
static byte ADMIN
          Client-to-server command to declare a user an operator, and server-to-client command to notify that a user has become an operator.
static byte ALIVE
          Client-to-server command to indicate that the connection is alive.
static byte AUTH
          Client-to-server command to request operator status.
static byte CARET
          Either-way command to indicate the caret position in a shared source file.
static byte CHAT
          Client-to-server command to send a chat line, and server-to-client command to relay a line to appear in chat logs.
static byte CLOSE
          Client-to-server command to request deleting the session.
static byte EDITOR
          Client-to-server command to set a new editor, and server-to-client command to notify of a new editor.
static byte ERR
          Server-to-client command to indicate that an error has occurred.
static byte FILE
          Server-to-client command to give the contents of an existing shared source file.
static byte HOST
          Server-to-client command giving a user's Internet hostname.
 long idle
          How long has this client been idle?
static byte IDLE
          Server-to-client command to indicate how long a user has been idle.
static byte INFO
          Client-to-server command requesting information on a user.
static byte INSERT
          Either-way command indicating an insertion in a shared source file.
static byte INTERP_IN
          Client-to-server command to make a query to the remote interpreter, and server-to-client command to notify clients of a pending query.
static byte INTERP_OUT
          Server-to-client command to notify of the result of a remote interpreter query.
static byte INTERRUPT
          Client-to-server command to request interrupting the remote interpreter.
static byte JOIN
          Server-to-client command indicating that a new user has joined the session.
static byte LOAD
          Client-to-server command to request loading all source files into the remote interpreter.
static byte LOADING
          Server-to-client command to indicate that source files are being loaded into the remote interpreter.
static byte LOGIN
          Client-to-server command to choose a handle.
static byte NAME
          Server-to-client command to indicate the initial presence of a user in the session.
static byte NAMES
          Server-to-client command to list current session users.
static byte NEW_FILE
          Client-to-server command to request creation of a new source file, and server-to-client command to notify of creation of a file.
static byte PART
          Server-to-client command indicating that a user has left the session.
static byte REMOVE
          Either-way command indicating a deletion from a shared source file.
static byte SESSION
          Client-to-server command to choose a session.
static byte WELCOME
          Server-to-client command to acknowledge successful login after SESSION and LOGIN.
 
Constructor Summary
CodeProtocol(java.net.Socket sock)
           
 
Method Summary
 void close()
          Close the connection
 java.lang.String hostname()
          Get hostname of remote end
 byte recvByte()
           
 int recvInt()
           
 long recvLong()
           
 java.util.Set recvSet()
           
 java.lang.String recvString()
           
 void sendAdmin(java.lang.String handle)
           
 void sendAlive()
           
 void sendAuth(java.lang.String user, java.lang.String pass)
           
 void sendByte(byte b)
           
 void sendCaret(java.lang.String fname, int pos, int len)
           
 void sendChat(java.lang.String msg)
           
 void sendEditor(java.lang.String handle)
           
 void sendErr(java.lang.String msg)
           
 void sendFile(java.lang.String name, java.lang.String contents)
           
 void sendHost(java.lang.String handle, java.lang.String host)
           
 void sendIdle(java.lang.String handle, long msecs)
           
 void sendInfo(java.lang.String handle)
           
 void sendInsert(java.lang.String fname, int pos, java.lang.String text)
           
 void sendInterpIn(java.lang.String msg)
           
 void sendInterpOut(java.lang.String msg)
           
 void sendInterrupt()
           
 void sendJoin(java.lang.String handle)
           
 void sendLoad()
           
 void sendLogin(java.lang.String name)
           
 void sendNames(java.util.Map names)
           
 void sendNewFile(java.lang.String name)
           
 void sendPart(java.lang.String handle)
           
 void sendRemove(java.lang.String fname, int pos, int len)
           
 void sendSession(java.lang.String name, java.lang.String lang, java.lang.String desc)
           
 void sendSet(java.util.Set s)
           
 void sendWelcome(java.lang.String lang)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SESSION

public static final byte SESSION
Client-to-server command to choose a session. First thing sent by a client. Followed by session name, language, and description.

See Also:
Constant Field Values

LOGIN

public static final byte LOGIN
Client-to-server command to choose a handle. Sent after SESSION. Followed by a handle.

See Also:
Constant Field Values

CHAT

public static final byte CHAT
Client-to-server command to send a chat line, and server-to-client command to relay a line to appear in chat logs. Followed by line text.

See Also:
Constant Field Values

WELCOME

public static final byte WELCOME
Server-to-client command to acknowledge successful login after SESSION and LOGIN.

See Also:
Constant Field Values

ERR

public static final byte ERR
Server-to-client command to indicate that an error has occurred. Followed by text description.

See Also:
Constant Field Values

NEW_FILE

public static final byte NEW_FILE
Client-to-server command to request creation of a new source file, and server-to-client command to notify of creation of a file. Followed by filename.

See Also:
Constant Field Values

EDITOR

public static final byte EDITOR
Client-to-server command to set a new editor, and server-to-client command to notify of a new editor. Followed by editor handle.

See Also:
Constant Field Values

NAMES

public static final byte NAMES
Server-to-client command to list current session users. Followed by Set of user handles, with '@' prepended for operators.

See Also:
Constant Field Values

JOIN

public static final byte JOIN
Server-to-client command indicating that a new user has joined the session. Followed by new user's handle.

See Also:
Constant Field Values

PART

public static final byte PART
Server-to-client command indicating that a user has left the session. Followed by leaving user's handle.

See Also:
Constant Field Values

INFO

public static final byte INFO
Client-to-server command requesting information on a user. Followed by that user's handle.

See Also:
Constant Field Values

HOST

public static final byte HOST
Server-to-client command giving a user's Internet hostname. Followed by a handle and hostname.

See Also:
Constant Field Values

FILE

public static final byte FILE
Server-to-client command to give the contents of an existing shared source file. Followed by a filename and contents.

See Also:
Constant Field Values

INSERT

public static final byte INSERT
Either-way command indicating an insertion in a shared source file. Followed by filename, index of insertion point in file contents, and text to insert.

See Also:
Constant Field Values

REMOVE

public static final byte REMOVE
Either-way command indicating a deletion from a shared source file. Followed by filename, index of beginning of deletion, and number of characters to delete.

See Also:
Constant Field Values

INTERP_IN

public static final byte INTERP_IN
Client-to-server command to make a query to the remote interpreter, and server-to-client command to notify clients of a pending query. Followed by query text.

See Also:
Constant Field Values

INTERP_OUT

public static final byte INTERP_OUT
Server-to-client command to notify of the result of a remote interpreter query. Followed by result text.

See Also:
Constant Field Values

ALIVE

public static final byte ALIVE
Client-to-server command to indicate that the connection is alive. Sent periodically.

See Also:
Constant Field Values

IDLE

public static final byte IDLE
Server-to-client command to indicate how long a user has been idle. Followed by handle of user in question.

See Also:
Constant Field Values

ADMIN

public static final byte ADMIN
Client-to-server command to declare a user an operator, and server-to-client command to notify that a user has become an operator. Followed by new operator's handle.

See Also:
Constant Field Values

NAME

public static final byte NAME
Server-to-client command to indicate the initial presence of a user in the session. Followed by a user handle, optionally with '@' prefixed to indicate operator status.

See Also:
Constant Field Values

AUTH

public static final byte AUTH
Client-to-server command to request operator status. Followed by a username and password.

See Also:
Constant Field Values

INTERRUPT

public static final byte INTERRUPT
Client-to-server command to request interrupting the remote interpreter.

See Also:
Constant Field Values

LOAD

public static final byte LOAD
Client-to-server command to request loading all source files into the remote interpreter.

See Also:
Constant Field Values

LOADING

public static final byte LOADING
Server-to-client command to indicate that source files are being loaded into the remote interpreter.

See Also:
Constant Field Values

CARET

public static final byte CARET
Either-way command to indicate the caret position in a shared source file. Followed by filename, index of last selected character, and index of first selected character.

See Also:
Constant Field Values

CLOSE

public static final byte CLOSE
Client-to-server command to request deleting the session.

See Also:
Constant Field Values

idle

public long idle
How long has this client been idle?


admin

public boolean admin
Is this a client-to-server connection belonging to an operator?

Constructor Detail

CodeProtocol

public CodeProtocol(java.net.Socket sock)
             throws CodeProtocol.Exn
Parameters:
sock - socket to use for communication
Method Detail

hostname

public java.lang.String hostname()
Get hostname of remote end


close

public void close()
Close the connection


recvString

public java.lang.String recvString()
                            throws CodeProtocol.Exn
CodeProtocol.Exn

recvSet

public java.util.Set recvSet()
                      throws CodeProtocol.Exn
CodeProtocol.Exn

recvByte

public byte recvByte()
              throws CodeProtocol.Exn
CodeProtocol.Exn

recvInt

public int recvInt()
            throws CodeProtocol.Exn
CodeProtocol.Exn

recvLong

public long recvLong()
              throws CodeProtocol.Exn
CodeProtocol.Exn

sendByte

public void sendByte(byte b)
              throws CodeProtocol.Exn
CodeProtocol.Exn

sendLogin

public void sendLogin(java.lang.String name)
               throws CodeProtocol.Exn
CodeProtocol.Exn

sendSession

public void sendSession(java.lang.String name,
                        java.lang.String lang,
                        java.lang.String desc)
                 throws CodeProtocol.Exn
CodeProtocol.Exn

sendChat

public void sendChat(java.lang.String msg)
              throws CodeProtocol.Exn
CodeProtocol.Exn

sendErr

public void sendErr(java.lang.String msg)
             throws CodeProtocol.Exn
CodeProtocol.Exn

sendNewFile

public void sendNewFile(java.lang.String name)
                 throws CodeProtocol.Exn
CodeProtocol.Exn

sendFile

public void sendFile(java.lang.String name,
                     java.lang.String contents)
              throws CodeProtocol.Exn
CodeProtocol.Exn

sendEditor

public void sendEditor(java.lang.String handle)
                throws CodeProtocol.Exn
CodeProtocol.Exn

sendAdmin

public void sendAdmin(java.lang.String handle)
               throws CodeProtocol.Exn
CodeProtocol.Exn

sendSet

public void sendSet(java.util.Set s)
             throws java.io.IOException
java.io.IOException

sendNames

public void sendNames(java.util.Map names)
               throws CodeProtocol.Exn
CodeProtocol.Exn

sendJoin

public void sendJoin(java.lang.String handle)
              throws CodeProtocol.Exn
CodeProtocol.Exn

sendPart

public void sendPart(java.lang.String handle)
              throws CodeProtocol.Exn
CodeProtocol.Exn

sendWelcome

public void sendWelcome(java.lang.String lang)
                 throws CodeProtocol.Exn
CodeProtocol.Exn

sendInfo

public void sendInfo(java.lang.String handle)
              throws CodeProtocol.Exn
CodeProtocol.Exn

sendHost

public void sendHost(java.lang.String handle,
                     java.lang.String host)
              throws CodeProtocol.Exn
CodeProtocol.Exn

sendRemove

public void sendRemove(java.lang.String fname,
                       int pos,
                       int len)
                throws CodeProtocol.Exn
CodeProtocol.Exn

sendInsert

public void sendInsert(java.lang.String fname,
                       int pos,
                       java.lang.String text)
                throws CodeProtocol.Exn
CodeProtocol.Exn

sendCaret

public void sendCaret(java.lang.String fname,
                      int pos,
                      int len)
               throws CodeProtocol.Exn
CodeProtocol.Exn

sendInterpIn

public void sendInterpIn(java.lang.String msg)
                  throws CodeProtocol.Exn
CodeProtocol.Exn

sendInterpOut

public void sendInterpOut(java.lang.String msg)
                   throws CodeProtocol.Exn
CodeProtocol.Exn

sendAlive

public void sendAlive()
               throws CodeProtocol.Exn
CodeProtocol.Exn

sendIdle

public void sendIdle(java.lang.String handle,
                     long msecs)
              throws CodeProtocol.Exn
CodeProtocol.Exn

sendAuth

public void sendAuth(java.lang.String user,
                     java.lang.String pass)
              throws CodeProtocol.Exn
CodeProtocol.Exn

sendInterrupt

public void sendInterrupt()
                   throws CodeProtocol.Exn
CodeProtocol.Exn

sendLoad

public void sendLoad()
              throws CodeProtocol.Exn
CodeProtocol.Exn