com.sun.jaw.impl.adaptor.udp
Class AdaptorSocket

java.lang.Object
  |
  +--com.sun.jaw.impl.adaptor.comm.AdaptorSocket
        |
        +--com.sun.jaw.impl.adaptor.udp.AdaptorSocket

public class AdaptorSocket
extends AdaptorSocket

The AdaptorSocket class provides a wrap-up of the socket to be used for an HTTP-based adaptor using UDP.


Fields inherited from class com.sun.jaw.impl.adaptor.comm.AdaptorSocket
port
 
Constructor Summary
AdaptorSocket()
          Constructs a HTTP/UDP adaptor socket.
AdaptorSocket(int port)
          Constructs a HTTP/UDP adaptor socket.
 
Method Summary
 java.lang.Object clone()
          Clone this adaptor socket.
 AdaptorSocket createClientSocket()
          Creates a socket to be used on the client side.
 AdaptorSocket createServerSocket(int port)
          Creates a socket to be used on the server side with the given port.
 void doBind()
          Bind to receive requests (usually used on server side).
 void doConnect(java.lang.String serverName, int serverPort)
          Connects to send a request (usually used on client side).
 void doDisconnect()
          Disconnects the adaptor socket.
 java.io.InputStream doGetInputStream()
          Returns an inputstream for this socket.
 java.io.InputStream doReceive()
          Waits for an incoming message.
 void doSend(java.lang.String header, byte[] content)
          Sends the given header and content to the peer.
 void doUnbind()
          Unbind (usually used on server side).
 java.net.InetAddress getLocalAddress()
          Returns the local IP address.
 int getLocalPort()
          Returns the local port number.
 int getMsgSize()
          Returns the message size of this adaptor socket.
 java.lang.String getProtocol()
          Returns the name of the "protocol" used ("udp").
 java.net.InetAddress getRemoteAddress()
          Returns the remote IP address.
 int getRemotePort()
          Returns the remote port number.
 void setMsgSize(int s)
          Set the message size of this adaptor socket (default 10240).
 java.lang.String toString()
          Returns a string representation of the object.
 
Methods inherited from class com.sun.jaw.impl.adaptor.comm.AdaptorSocket
getTimeout, setTimeout
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AdaptorSocket

public AdaptorSocket()
Constructs a HTTP/UDP adaptor socket.

AdaptorSocket

public AdaptorSocket(int port)
Constructs a HTTP/UDP adaptor socket.
Parameters:
p - The port number.
Method Detail

createServerSocket

public AdaptorSocket createServerSocket(int port)
Creates a socket to be used on the server side with the given port.
Parameters:
port - The port number.
Returns:
The adaptor socket.
Overrides:
createServerSocket in class AdaptorSocket

createClientSocket

public AdaptorSocket createClientSocket()
Creates a socket to be used on the client side.

No port is provided as the client does not "bind".

Returns:
The adaptor socket.
Overrides:
createClientSocket in class AdaptorSocket

getProtocol

public java.lang.String getProtocol()
Returns the name of the "protocol" used ("udp").
Returns:
The string "udp".
Overrides:
getProtocol in class AdaptorSocket

doBind

public void doBind()
            throws java.io.IOException
Bind to receive requests (usually used on server side).
Throws:
java.io.IOException - Signals that an I/O exception of some sort has occurred.
Overrides:
doBind in class AdaptorSocket

doUnbind

public void doUnbind()
              throws java.io.IOException
Unbind (usually used on server side).
Throws:
java.io.IOException - Signals that an I/O exception of some sort has occurred.
Overrides:
doUnbind in class AdaptorSocket

doConnect

public void doConnect(java.lang.String serverName,
                      int serverPort)
               throws java.net.UnknownHostException,
                      java.io.IOException
Connects to send a request (usually used on client side).
Parameters:
serverName - The name of the server to connect the socket to.
serverPort - The port number of the specified server.
Throws:
java.net.UnknownHostException - The IP address of the specified host could not be determined.
java.io.IOException - Signals that an I/O exception of some sort has occurred.
CommunicationException - A communications problem occurred.
Overrides:
doConnect in class AdaptorSocket

doDisconnect

public void doDisconnect()
                  throws java.io.IOException,
                         CommunicationException
Disconnects the adaptor socket.

Can be used on both server and client sides. On the client side, disconnects the socket used when connecting. On the server side, disconnects the socket involved in the communication with the client; it's not usually the socket used for binding.

Throws:
java.io.IOException - Signals that an I/O exception of some sort has occurred.
CommunicationException - A communications problem occurred.
Overrides:
doDisconnect in class AdaptorSocket

doSend

public void doSend(java.lang.String header,
                   byte[] content)
            throws java.io.IOException
Sends the given header and content to the peer.

On the client side, it's usually the initiated request, and on the server side, it's the reply to the client's request.

Parameters:
header - The header to be sent.
content - The content to be sent.
Throws:
java.io.IOException - Signals that an I/O exception of some sort has occurred.
Overrides:
doSend in class AdaptorSocket

doReceive

public java.io.InputStream doReceive()
                              throws java.io.IOException
Waits for an incoming message.

On the server side, wait for a request from the client, and on the client side, wait for the reply to the client's request.

Returns:
The input stream for this adaptor socket.
Throws:
java.io.IOException - Signals that an I/O exception of some sort has occurred.
Overrides:
doReceive in class AdaptorSocket

doGetInputStream

public java.io.InputStream doGetInputStream()
                                     throws java.io.IOException
Returns an inputstream for this socket.
Returns:
The input stream for this adaptor socket.
Throws:
java.io.IOException - Signals that an I/O exception of some sort has occurred.
Overrides:
doGetInputStream in class AdaptorSocket

getLocalAddress

public java.net.InetAddress getLocalAddress()
Returns the local IP address.
Returns:
The local IP address.
Overrides:
getLocalAddress in class AdaptorSocket

getLocalPort

public int getLocalPort()
Returns the local port number.
Returns:
The local port number.
Overrides:
getLocalPort in class AdaptorSocket

getRemoteAddress

public java.net.InetAddress getRemoteAddress()
Returns the remote IP address.
Returns:
The remote IP address.
Overrides:
getRemoteAddress in class AdaptorSocket

getRemotePort

public int getRemotePort()
Returns the remote port number.
Returns:
The remote port number.
Overrides:
getRemotePort in class AdaptorSocket

toString

public java.lang.String toString()
Returns a string representation of the object.
Returns:
A string representation of the object.
Overrides:
toString in class java.lang.Object

getMsgSize

public int getMsgSize()
Returns the message size of this adaptor socket.
Returns:
The socket message size.

setMsgSize

public void setMsgSize(int s)
Set the message size of this adaptor socket (default 10240).
Parameters:
s - The adaptor socket message size.

clone

public java.lang.Object clone()
Clone this adaptor socket.
Overrides:
clone in class AdaptorSocket