mobnet
Class Socket

java.lang.Object
  extended bymobnet.Socket
All Implemented Interfaces:
java.lang.Runnable

public class Socket
extends java.lang.Object
implements java.lang.Runnable

Socket.java MobNet implementation of java.net.Socket NOT FULLY IMPLEMENTED

Author:
Avi TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates

Constructor Summary
Socket(int port, java.lang.String destIP)
          Constructor for Socket class.
Socket(int port, java.lang.String destIP, boolean returnsetup)
          This constuctor is called by a server in order to set up a reciprical Socket to the client.
 
Method Summary
 void close()
          Close the Socket CURRENTLY THIS METHOD DOES NOTHING
 InputStream getInputStream()
          Returns the InputStream bound to this Socket
 boolean getKeepAlive()
          NOT IMPLEMENTED
 boolean getOOBInline()
          NOT IMPLEMENTED
 OutputStream getOutputStream()
          Returns the OutputStream bound to this Socket
 int getPort()
           
 boolean getReuseAddress()
          NOT FULLY IMPLEMENTED Tests if SO_REUSEADDR is enabled.
 int getSoLinger()
          NOT FULLY IMPLEMENTED Returns setting for SO_LINGER.
 int getSoTimeout()
          Returns setting for SO_TIMEOUT.
 java.lang.String getSrcIP()
           
 void insert(Packet p)
          This method is used by the Singleton Manager and indirectly the Dispatcher to insert a Packet into the Socket
 void run()
          Socket implements runnable.
 void setReady()
          Called by a ServerSocket when it has finished instantiating the reciprocal Socket to the client.
 void setSoTimeout(int timeout)
          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

Socket

public Socket(int port,
              java.lang.String destIP)
       throws java.io.IOException
Constructor for Socket class. Socket blocks while waiting to be connected to a ServerSocket.

Parameters:
port - Port to which the Socket is to be bound
destIP - IP to which the IP is to be bound

Socket

public Socket(int port,
              java.lang.String destIP,
              boolean returnsetup)
       throws java.io.IOException
This constuctor is called by a server in order to set up a reciprical Socket to the client.

Parameters:
port - The port to which the Socket is to be bound
destIP - The IP address to which the Socket is to be bound
returnsetup - Boolean to differentiate this constructor with the other constructor. This constructor ensures that the Socket does not try and connect to a Server, as this Socket will be connecting to a client which as already set up a socket to the Server.
Method Detail

setReady

public void setReady()
Called by a ServerSocket when it has finished instantiating the reciprocal Socket to the client. Sets the client side socket to be ready to use.


getPort

public int getPort()
Returns:
The port which this Socket is bound to

getSrcIP

public java.lang.String getSrcIP()
Returns:
The IP Address of the node that instantiated the Socket

getInputStream

public InputStream getInputStream()
                           throws java.io.IOException
Returns the InputStream bound to this Socket

Returns:
The InputStream bound to this Socket
Throws:
java.io.IOException

getOutputStream

public OutputStream getOutputStream()
                             throws java.io.IOException
Returns the OutputStream bound to this Socket

Returns:
The OutputStream bound to this Socket
Throws:
java.io.IOException

setSoTimeout

public void setSoTimeout(int timeout)
                  throws java.net.SocketException
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the Socket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.

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

insert

public void insert(Packet p)
This method is used by the Singleton Manager and indirectly the Dispatcher to insert a Packet into the Socket

Parameters:
p - The Packet to be inserted

close

public void close()
Close the Socket CURRENTLY THIS METHOD DOES NOTHING


getKeepAlive

public boolean getKeepAlive()
                     throws java.net.SocketException
NOT IMPLEMENTED

Returns:
Throws:
java.net.SocketException

getOOBInline

public boolean getOOBInline()
                     throws java.net.SocketException
NOT IMPLEMENTED

Returns:
Throws:
java.net.SocketException

getReuseAddress

public boolean getReuseAddress()
                        throws java.net.SocketException
NOT FULLY IMPLEMENTED Tests if SO_REUSEADDR is enabled. Always Returns false

Returns:
Always returns false
Throws:
java.net.SocketException

getSoLinger

public int getSoLinger()
                throws java.net.SocketException
NOT FULLY IMPLEMENTED Returns setting for SO_LINGER. -1 returns implies that the option is disabled.

Returns:
Always returns disabled at present
Throws:
java.net.SocketException

getSoTimeout

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

Returns:
At present always returns 0, disabled
Throws:
java.net.SocketException

run

public void run()
Socket implements runnable. So this run() used to start the Socket. The Socket then gets Packets from its Input Buffer and sends them to the InputStream.

Specified by:
run in interface java.lang.Runnable