ewe.net
Class SocketMaker

java.lang.Object
  extended byewe.data.DataObject
      extended byewe.data.LiveObject
          extended byewe.net.SocketMaker
All Implemented Interfaces:
Comparable, Copyable, DataUnit, FieldListener, LiveData

public class SocketMaker
extends LiveObject

This can interactively create a Socket or ServerSocket for connection to a server or client.


Field Summary
static String AnyHostName
           
 boolean canSelectType
          This allows users to select the type of connection.
 String hostName
          The name of the host to connect to.
static int INFRA_RED
          This should be used with the "type" member.
 boolean isServer
          This says whether a ServerSocket is to be created.
static int LOCAL_SOCKET
          This should be used with the "type" member.
 int port
          The port number to connect to.
static int REMOTE_SERVICE
          This should be used with the "type" member.
static int REMOTE_SOCKET
          This should be used with the "type" member.
 String serviceName
          Use this if you want to connect to a remote service (via the RemoteConnection) or a providing a remote service.
 int timeout
          This is the timeout time in seconds to wait for a successful connection.
 String title
          This is the title of the form that is displayed if you are doing an interactive connection.
 int type
          By default this is LOCAL_SOCKET
 
Constructor Summary
SocketMaker(int type, boolean isServer, String title)
          Creates a SocketMaker with the specified type, wether it is a server and the title of the dialog box if it is displayed.
 
Method Summary
 void action(String fieldName, Editor f)
          This gets called by action(FieldTransfer ft,Editor ed) and by fieldChanged(FieldTransfer ft,Editor ed) if the field changed is a menu item.
 void addToPanel(CellPanel cp, Editor f, int which)
          Override this to provide the user interface for editing the Object.
 void fieldChanged(FieldTransfer ft, Editor f)
          This implements the fieldChanged() method in FieldListener.
 Handle getClientServerConnection(Frame parent, int options, boolean showCancel)
           
 Socket getConnection(boolean showSelectBox, boolean showCancel)
          This gets a fully connected Socket.
 Socket getConnection(Frame parent, int options, boolean showCancel)
          This is the same as the other getConnection() except it will execute the select connection dialog box with the specified parent and options (e.g.
 Socket getConnection(ServerSocket ss, Frame parent, boolean showCancel, int timeoutInSeconds)
          This waits for an incoming connection on the ServerSocket for the timeout period (given in seconds).
 String getError()
          This MAY return additional information if there was an error during socket creation.
 Object getSocket(boolean showSelectBox, boolean showCancel)
          This is used to get either a Socket or ServerSocket using the parameters setup for this SocketMaker.
 Object getSocket(Frame parent, int options, boolean showCancel)
          This is the same as the other getSocket() except it will execute the dialog box with the specified parent and options (e.g.
 Object[] getTwoWayConnection(boolean showSelectBox)
           
 Handle getTwoWayConnection(boolean showSelectBox, boolean showCancel)
           
 Handle getTwoWayConnection(Frame parent, int options, boolean showCancel)
           
 Object makeClientServerConnection(Frame parent, int options, boolean showCancel)
           
static Object makeInfraRedConnection(int port, int timeoutInSeconds, boolean showCancel)
           
static Socket[] pipe()
          This method creates two Sockets on the local host connected together.
 boolean showInitialFrame(Frame parent, int options)
           
 
Methods inherited from class ewe.data.LiveObject
action, addMeToPanel, addObjectToPanel, decode, decoded, decodeFields, enableEditorScrolling, encode, encoded, encodeFields, fieldChanged, fieldEvent, getEditor, getEditorScroller, getIcon, getName, input, makeNewEditor, runAsApp, textDecode, textEncode
 
Methods inherited from class ewe.data.DataObject
_getSetField, appendAllFields, compareTo, copied, copyFrom, equals, getCopy, getDeclaredField, getDeclaredFieldValue, getDeclaredFieldValue, getFieldList, getFieldList, getMyFieldList, getNew
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, toString
 
Methods inherited from interface ewe.data.DataUnit
copyFrom, getNew
 
Methods inherited from interface ewe.util.Copyable
getCopy
 
Methods inherited from interface ewe.util.Comparable
compareTo
 

Field Detail

LOCAL_SOCKET

public static final int LOCAL_SOCKET
This should be used with the "type" member.

See Also:
Constant Field Values

INFRA_RED

public static final int INFRA_RED
This should be used with the "type" member.

See Also:
Constant Field Values

REMOTE_SERVICE

public static final int REMOTE_SERVICE
This should be used with the "type" member.

See Also:
Constant Field Values

REMOTE_SOCKET

public static final int REMOTE_SOCKET
This should be used with the "type" member. This one should not be used if you are creating a server.

See Also:
Constant Field Values

type

public int type
By default this is LOCAL_SOCKET


AnyHostName

public static String AnyHostName

hostName

public String hostName
The name of the host to connect to. Not used for INFRA_RED.


port

public int port
The port number to connect to. Not used for INFRA_RED. If isServer is true, then this can be zero and its value can be determined after calling getSocket().


serviceName

public String serviceName
Use this if you want to connect to a remote service (via the RemoteConnection) or a providing a remote service.


isServer

public boolean isServer
This says whether a ServerSocket is to be created.


timeout

public int timeout
This is the timeout time in seconds to wait for a successful connection.


title

public String title
This is the title of the form that is displayed if you are doing an interactive connection.


canSelectType

public boolean canSelectType
This allows users to select the type of connection.

Constructor Detail

SocketMaker

public SocketMaker(int type,
                   boolean isServer,
                   String title)
Creates a SocketMaker with the specified type, wether it is a server and the title of the dialog box if it is displayed.

Method Detail

getError

public String getError()
This MAY return additional information if there was an error during socket creation.

Returns:
An error description or null if there was no error.

addToPanel

public void addToPanel(CellPanel cp,
                       Editor f,
                       int which)
Description copied from class: LiveObject
Override this to provide the user interface for editing the Object. Add all your controls to the CellPanel cp, and your fields to the Editor ed. The options parameter may be used to specify a different Editor for the Object for different situations - it is the same parameter that is passed to the LiveData.getEditor(int options) call.

Overrides:
addToPanel in class LiveObject

fieldChanged

public void fieldChanged(FieldTransfer ft,
                         Editor f)
Description copied from class: LiveObject
This implements the fieldChanged() method in FieldListener. It operates like like this:

If the field is of type ewe.ui.MenuItem then the method action(String name,Editor ed) is called with the "name" parameter being set to the "action" member of the selected MenuItem.

Otherwise the fieldChanged(String fieldName,Editor ed) method is called with the fieldName of the FieldTransfer object.

Specified by:
fieldChanged in interface FieldListener
Overrides:
fieldChanged in class LiveObject
Parameters:
ft - The FieldTransfer object representing the changed field.
f - The Editor from which the event came.

action

public void action(String fieldName,
                   Editor f)
Description copied from class: LiveObject
This gets called by action(FieldTransfer ft,Editor ed) and by fieldChanged(FieldTransfer ft,Editor ed) if the field changed is a menu item. By default it will look for a method called void _action(Editor ed) and if it finds it, it will be executed.

Overrides:
action in class LiveObject

getSocket

public Object getSocket(boolean showSelectBox,
                        boolean showCancel)
This is used to get either a Socket or ServerSocket using the parameters setup for this SocketMaker. If showSelectBox is true, then a dialog box will appear for the user to change the parameters of the socket. If showCancel is true, a box will appear during socket creation and connection so the user can cancel the operation.

The method will return a Socket (isServer is false) or a ServerSocket (isServer is true) or null if the socket could not be created or if the user canceled the operation.


showInitialFrame

public boolean showInitialFrame(Frame parent,
                                int options)

getTwoWayConnection

public Object[] getTwoWayConnection(boolean showSelectBox)

getTwoWayConnection

public Handle getTwoWayConnection(boolean showSelectBox,
                                  boolean showCancel)

getTwoWayConnection

public Handle getTwoWayConnection(Frame parent,
                                  int options,
                                  boolean showCancel)

makeInfraRedConnection

public static Object makeInfraRedConnection(int port,
                                            int timeoutInSeconds,
                                            boolean showCancel)
                                     throws IOException
Throws:
IOException

makeClientServerConnection

public Object makeClientServerConnection(Frame parent,
                                         int options,
                                         boolean showCancel)
                                  throws IOException
Throws:
IOException

getClientServerConnection

public Handle getClientServerConnection(Frame parent,
                                        int options,
                                        boolean showCancel)

getSocket

public Object getSocket(Frame parent,
                        int options,
                        boolean showCancel)
This is the same as the other getSocket() except it will execute the dialog box with the specified parent and options (e.g. Gui.FILL_FRAME).


getConnection

public Socket getConnection(ServerSocket ss,
                            Frame parent,
                            boolean showCancel,
                            int timeoutInSeconds)
This waits for an incoming connection on the ServerSocket for the timeout period (given in seconds). It will optionally show a cancel box. It will return a connected socket or null on failure. It will not close the server socket. If timeoutInSeconds is -1, then there will be no timeout.


getConnection

public Socket getConnection(boolean showSelectBox,
                            boolean showCancel)
This gets a fully connected Socket. This first calls getSocket() with the same parameter and if isServer is true (getSocket() returns a ServerSocket), it will wait until a client connects and then return connected socket and close the ServerSocket. If isServer is false then it returns the Socket returned by getSocket() which will be a socket connected to a server.


getConnection

public Socket getConnection(Frame parent,
                            int options,
                            boolean showCancel)
This is the same as the other getConnection() except it will execute the select connection dialog box with the specified parent and options (e.g. Gui.FILL_FRAME).


pipe

public static Socket[] pipe()
                     throws IOException
This method creates two Sockets on the local host connected together.

Throws:
IOException