edu.cmu.sphinx.util
Class SocketCommandClient

java.lang.Object
  extended byedu.cmu.sphinx.util.SocketCommandClient

public class SocketCommandClient
extends java.lang.Object

A client for a socketed command interpreter. Hooks up to a socketed command interpreter and allows the sending of commands.

See Also:
CommandInterpreter

Constructor Summary
SocketCommandClient()
          Creats a SocketCommandClient with no connection open must be called.
SocketCommandClient(java.lang.String host, int port)
          Creates a socket command client at the given host and port.
 
Method Summary
 void close()
          Closes the socket connection
 java.lang.String getResponse()
          Gets a response
 int getSoTimeout()
          Returns the SO_TIMEOUT of the Socket that this client uses. 0 returns implies that the option is disabled (i.e., timeout of infinity).
 boolean isResponse()
          is a response
static void main(java.lang.String[] args)
          manual tester for the command interpreter.
 void open(java.lang.String aHost, int aPort)
          Opens a socket connection
 boolean sendCommand(java.lang.String command)
          sends a command, retries on error which will attempt to repair a dead socket
 java.lang.String sendCommandGetResponse(java.lang.String command)
          sends a command get a response
 void setSoTimeout(int millisecs)
          Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketCommandClient

public SocketCommandClient(java.lang.String host,
                           int port)
                    throws java.io.IOException
Creates a socket command client at the given host and port.

Parameters:
host - the host machine
port - the port to use

SocketCommandClient

public SocketCommandClient()
Creats a SocketCommandClient with no connection open must be called.

Method Detail

open

public void open(java.lang.String aHost,
                 int aPort)
          throws java.io.IOException
Opens a socket connection

Parameters:
aHost - the host to connect to
aPort - the port to connect to
Throws:
java.io.IOException - if connection fails

getSoTimeout

public int getSoTimeout()
                 throws java.net.SocketException
Returns the SO_TIMEOUT of the Socket that this client uses. 0 returns implies that the option is disabled (i.e., timeout of infinity).

Throws:
java.net.SocketException

setSoTimeout

public void setSoTimeout(int millisecs)
                  throws java.net.SocketException
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.

Parameters:
millisecs - the timeout in milliseconds
Throws:
java.net.SocketException

sendCommand

public boolean sendCommand(java.lang.String command)
sends a command, retries on error which will attempt to repair a dead socket

Parameters:
command - the command
Returns:
true if command was sent ok

getResponse

public java.lang.String getResponse()
Gets a response

Returns:
the response or null if error

isResponse

public boolean isResponse()
is a response

Returns:
the response or null if error

sendCommandGetResponse

public java.lang.String sendCommandGetResponse(java.lang.String command)
sends a command get a response

Parameters:
command - the command to send
Returns:
the response or null if error

close

public void close()
Closes the socket connection


main

public static void main(java.lang.String[] args)
manual tester for the command interpreter.