|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectewe.sys.TaskObject
ewe.net.ClientServerConnector
This can be used to easily create a Client/Server connection over TCP/IP or through the EweSync RemoteConnection.
| Field Summary | |
boolean |
acceptOnlyOneConnection
If this is set true then after the initial connection, no more connections will be accepted and the server socket will be closed. |
protected Handle |
connecting
|
boolean |
dontShowCancel
Set this true if you don't want to show the cancel box. |
String |
hostOrService
|
static int |
INFRA_RED
This is a type to be used in the constructor. |
boolean |
isClient
This will be set if a connection is made and this connector is considered the client. |
boolean |
isServer
This will be set if a connection is made and this connector is considered the server. |
Frame |
parentFrame
You can optionanlly set this. |
int |
port
|
static int |
REMOTE_SERVICE
This is a type to be used in the constructor. |
static int |
REMOTE_TCP_SOCKET
This is a type to be used in the constructor. |
ServerSocket |
server
This is the server that will be listened to after the initial connection. |
boolean |
showSelectionScreen
Set this true to let the user change the connection settings. |
protected SocketMaker |
socketMaker
This will be created during the connection setup. |
static int |
TCP_SOCKET
This is a type to be used in the constructor. |
int |
timeoutInSeconds
This defaults to 30 seconds. |
int |
type
|
| Fields inherited from class ewe.sys.TaskObject |
handle, interruptThreadToStop, myThread, napIterations, napTime, shouldStop |
| Constructor Summary | |
ClientServerConnector(boolean amServer,
int port)
This is for Infra-Red connections only - it creates a client-server connection over the infra-red port where this entity will act as either the server or client as specified by the amServer parameter. |
|
ClientServerConnector(boolean amServer,
int type,
String hostOrService,
int port)
This creates a client-server connection where this entity will act as either the server or client as specified by the amServer parameter. |
|
ClientServerConnector(int port)
This is for Infra-Red connections only - it creates a negotiated client-server connection over the infra-red port. |
|
ClientServerConnector(int type,
String hostOrService,
int port)
Create a negotiated client-server connection between two initially peer entities. |
|
| Method Summary | |
protected abstract void |
client(Socket s)
This gets called on the first connection and if it is determined that I am the client. |
Handle |
connect()
Start the connection process and immediately return a Handle to indicate its progress. |
Socket |
connectToServer()
This is used to make another connection to the server process on the same server port where the initial connection was made. |
protected void |
doRun()
Override this method if you want to use an mThread to run your Task. |
protected void |
doStop(int reason)
This method, by default, sets the shouldStop variable to true. |
protected abstract void |
server(Socket client,
boolean firstConnection)
This gets called every time the client connects - including the initial connection. |
void |
stopServer()
If the connector is waiting for extra client connections this will close the server socket. |
boolean |
waitOnConnection()
Start the connecton and wait until the connection is made. |
| Methods inherited from class ewe.sys.TaskObject |
checkAbortFail, checkFailure, doStart, exec, getHandle, nap, run, setNapTime, show, sleep, start, startTask, stopTask, waitOn, waitOnAny, waitOnSuccess, yield, yield |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, toString |
| Field Detail |
public static final int TCP_SOCKET
public static final int REMOTE_TCP_SOCKET
public static final int INFRA_RED
public static final int REMOTE_SERVICE
public int type
public String hostOrService
public int port
public boolean showSelectionScreen
public int timeoutInSeconds
public boolean dontShowCancel
public Frame parentFrame
public boolean acceptOnlyOneConnection
public ServerSocket server
protected Handle connecting
public boolean isClient
public boolean isServer
protected SocketMaker socketMaker
| Constructor Detail |
public ClientServerConnector(int type,
String hostOrService,
int port)
This type of connection will be initiated at both entities and a negotiation will be done when both connect to decide which will act as the server and which as the client. This is not recommended on all platforms since the TCP/IP implementation on some (e.g. Win98) is flawed and this may not always work. The type of connection where one is definitely the client and the other the server is usually better.
Note that doing this over the REMOTE_SERVICE will usually work correctly since in this case the desktop will always be the server and the mobile device will always be the client.
type - either TCP_SOCKET, REMOTE_TCP_SOCKET, REMOTE_SERVICE or INFRA_REDhostOrService - for TCP_SOCKET or REMOTE_TCP_SOCKET it should be the host name,
for REMOTE_SERVICE (over the EweSync connection) it should be the service name, and for
INFRA_RED it should be null.port - The port number to use. This should not be 0.public ClientServerConnector(int port)
public ClientServerConnector(boolean amServer,
int type,
String hostOrService,
int port)
amServer - if this is true then this entity is the server, otherwise it is the client.type - either TCP_SOCKET, REMOTE_TCP_SOCKET, REMOTE_SERVICE or INFRA_REDhostOrService - for TCP_SOCKET or REMOTE_TCP_SOCKET it should be the host name,
for REMOTE_SERVICE (over the EweSync connection) it should be the service name, and for
INFRA_RED it should be null.port - The port number to use. This should not be 0.
public ClientServerConnector(boolean amServer,
int port)
amServer - if this is true then this entity is the server, otherwise it is the client.port - the port number to use (which should not be 0).| Method Detail |
public void stopServer()
protected void doStop(int reason)
TaskObjectYou can override this to provide a different method of stopping the task.
doStop in class TaskObjectreason - some task specific reason for stopping. There are no pre-defined reasons.
public Socket connectToServer()
throws IOException
IOException - if a connection could not be made.
IllegalStateException - if this connector is not the client.public Handle connect()
public boolean waitOnConnection()
throws IOException
IOException - if the connection failed.protected abstract void client(Socket s)
protected abstract void server(Socket client,
boolean firstConnection)
client - The client that is connected.firstConnection - this is true if this is the initial connection.protected void doRun()
TaskObject
doRun in class TaskObject
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||