|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectewe.net.ServerSocket
A server socket is used to wait for incoming TCP/IP connections.
This operates similar to the java.net.ServerSocket.
If you want to accept connections from a device via the infra-red port, set the host to be "infra-red" and set the port to be 0 when creating the ServerSocket.
| Field Summary | |
static int |
CHECK_ACCEPT
|
static int |
CHECK_LISTEN
|
protected Object |
localHost
|
protected int |
localPortNotUsed
|
| Constructor Summary | |
ServerSocket(int port)
Create a ServerSocket to listen on the local host on a specific port. |
|
ServerSocket(int port,
int backlog)
Create a server socket on the local host at the specified port number. |
|
ServerSocket(int port,
int backlog,
InetAddress address)
Creates a server socket at the specified port in blocking mode. |
|
ServerSocket(int port,
int backlog,
String address,
IOHandle handle)
You should use one of the other ServerSocket constructors which throw an IOException on failure. |
|
ServerSocket(int port,
IOHandle handle)
Creates a server socket at the specified port in non-blocking mode. |
|
ServerSocket(String host,
int port)
Create a ServerSocket to listen on the local host for a specific address, on a specific port. |
|
| Method Summary | |
Socket |
accept()
This will accept an incoming TCP/IP connection - blocking version. |
IOHandle |
accept(IOHandle nullHandle)
This will accept an incoming TCP/IP connection - non-blocking version. |
void |
close()
|
InetAddress |
getInetAddress()
|
int |
getLocalPort()
This gets the local port the socket is listening on. |
boolean |
isOpen()
|
protected int |
pauseUntilAccepted(int howLong)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, toString |
| Field Detail |
protected Object localHost
protected int localPortNotUsed
public static final int CHECK_LISTEN
public static final int CHECK_ACCEPT
| Constructor Detail |
public ServerSocket(int port,
int backlog,
InetAddress address)
throws IOException
If you want to connect to accept connections from a device via the infra-red port, set the host to be "infra-red" and set the port to be 0 when creating the ServerSocket.
address - The address of the local machine to listen to.port - The port number to listen to. If this is 0, then a new and unused port number will be used.
Use getLocalPort() to determine which port was chosen for the ServerSocket.backlog - The number of backlogged connections to accept.
public ServerSocket(int port,
int backlog)
throws IOException
This method blocks the current thread until the ServerSocket is created or an exception is thrown.
port - The port to listen for connections on. If the port number is zero a new
port number will be assigned. To get the port number actually used, call getLocalPort().backlog - The number of backlogged connections to accept.
IOException - If an error occurs while trying to connect to the specified port.
public ServerSocket(String host,
int port)
throws IOException
host - The host name to listen to. If this is "infra-red" then the ServerSocket will listen
on the infra-red port on the specified port.port - The port number to listen to. If this is 0, then a new and unused port number will be used (This
also works for "infra-red").
Use getLocalPort() to determine which port was chosen for the ServerSocket.
IOException - If an error occurs while trying to connect to the specified port.
public ServerSocket(int port,
IOHandle handle)
port - The port number to listen to. If this is 0, then a new and unused port number will be used.
Use getLocalPort() to determine which port was chosen for the ServerSocket.handle - if this is not null then the method will return immediately
and you can use the handle to wait on the handle for success or failure. If handle is
null, then the method will not return until the open operation succeeds or fails, blocking
all other Threads until it is done.
public ServerSocket(int port)
throws IOException
port - The port number to listen to. If this is 0, then a new and unused port number will be used.
Use getLocalPort() to determine which port was chosen for the ServerSocket.
IOException - If an error occurs while trying to connect to the specified port.
public ServerSocket(int port,
int backlog,
String address,
IOHandle handle)
This method starts the process for opening a ServerSocket at the specified IP address for the local host. If the handle parameter is not null, then the method will return immediately and you can use the handle to wait on the handle for success or failure. If handle is null, then the method will not return until the open operation succeeds or fails, blocking all other Threads until it is done. The isOpen() method can then be used to determine if the ServerSocket was created successfully.
The address may be a name for the local host or an IP address for the local host. Since the Local host may have multiple addresses you can use InetAddress.getAllByName(InetAddress.getLocalHostName(),null) to get a list of available InetAddresses for the local host. You can then specify precisely which one you want to use by passing the value returned by InetAddress.getHostAddress() to the constructor for ServerSocket.
port - The port to listen on. If this is zero then any available port is used.
You can call getLocalPort() after a successful.backlog - the backlog of pending connections allowed on the ServerSocket.address - the local host address to bind to, or null to bind to any on the local host.handle - if this is not null then the method will return immediately
and you can use the handle to wait on the handle for success or failure. If handle is
null, then the method will not return until the open operation succeeds or fails, blocking
all other Threads until it is done.| Method Detail |
public void close()
throws IOException
IOExceptionpublic boolean isOpen()
public int getLocalPort()
public InetAddress getInetAddress()
public Socket accept()
throws IOException
IOExceptionpublic IOHandle accept(IOHandle nullHandle)
nullHandle - should always be null - since a new Handle is always returned.
protected int pauseUntilAccepted(int howLong)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||