Class powersoft.jcm.net.BaseSocket
All Packages Class Hierarchy This Package Previous Next Index
Class powersoft.jcm.net.BaseSocket
java.lang.Object
|
+----powersoft.jcm.net.BaseSocket
- public class BaseSocket
- extends Object
- implements SocketExceptionCode
This class serves as the abstract base class for the ServerSocket
and Socket classes.
- See Also:
- Socket, ServerSocket
-
_asynchronous
-
-
_created
-
-
_errorVector
-
-
_getHostByNameThread
-
-
_hostResolvedVector
-
-
_localPort
-
-
_remoteAddr
-
-
_remotePort
-
-
_root
-
-
BaseSocket()
- Instantiates a BaseSocket object.
-
addSocketErrorListener(SocketErrorListener)
-
-
addSocketHostResolvedListener(SocketHostResolvedListener)
-
-
close()
- Closes the socket.
-
getAsynchronous()
- Determines whether the socket is asynchronous or not.
-
getLastError()
- Gets the error code of the last operation on the socket that failed.
-
getLocalHostAddress()
- Gets the internet address of the local host for the socket.
-
getLocalHostName()
- Gets the name of the local host for the socket.
-
getLocalPort()
- Gets the local port used by the socket.
-
getRemoteHostName()
- Gets the name of the remote host for a connected stream socket.
-
getRemoteInetAddress()
- Gets the internet address of the remote host for a connected stream
socket.
-
getRemotePort()
- Gets the port of the remote host for a connected stream socket.
-
getSocketErrorListeners()
-
-
getSocketHostResolvedListeners()
-
-
handleSocketError(SocketErrorEvent)
- SocketErrorEvent handler
-
handleSocketHostResolved(SocketHostResolvedEvent)
- SocketHostResolvedEvent handler
-
RaiseError(byte)
-
-
RaiseError(byte, Exception)
-
-
removeSocketErrorListener(SocketErrorListener)
-
-
removeSocketHostResolvedListener(SocketHostResolvedListener)
-
-
ResetAsynchronous(boolean)
-
-
resetLastError()
- Resets the error code of the last operation on the socket that failed
to SockENoError.
-
ResetLocalPort(int)
-
-
ResetRemotePort(int)
-
-
setAsynchronous(boolean)
- Sets the mode of the socket to asynchronous or non-asynchronous.
-
setLocalPort(int)
- Sets the local port to be used by the socket.
-
setRemoteHostName(String)
- Sets the name of the remote host in preparation of a connect
operation on a stream socket.
-
setRemotePort(int)
- Sets the port of the remote host in preparation of a connect
operation on a stream socket.
_asynchronous
protected boolean _asynchronous
_created
protected boolean _created
_remoteAddr
protected InetAddress _remoteAddr
_remotePort
protected int _remotePort
_localPort
protected int _localPort
_root
protected BaseSocket _root
_getHostByNameThread
protected GetHostByNameThread _getHostByNameThread
_hostResolvedVector
protected EventListenerVector _hostResolvedVector
_errorVector
protected EventListenerVector _errorVector
BaseSocket
protected BaseSocket()
- Instantiates a BaseSocket object. This is to be used by the
ServerSocket and Socket classes only
addSocketErrorListener
public synchronized void addSocketErrorListener(SocketErrorListener l)
getSocketErrorListeners
public synchronized EventListenerVector getSocketErrorListeners()
handleSocketError
public synchronized void handleSocketError(SocketErrorEvent data)
- SocketErrorEvent handler
removeSocketErrorListener
public synchronized void removeSocketErrorListener(SocketErrorListener l)
addSocketHostResolvedListener
public synchronized void addSocketHostResolvedListener(SocketHostResolvedListener l)
getSocketHostResolvedListeners
public synchronized EventListenerVector getSocketHostResolvedListeners()
handleSocketHostResolved
public synchronized void handleSocketHostResolved(SocketHostResolvedEvent data)
- SocketHostResolvedEvent handler
removeSocketHostResolvedListener
public synchronized void removeSocketHostResolvedListener(SocketHostResolvedListener l)
getAsynchronous
public boolean getAsynchronous()
- Determines whether the socket is asynchronous or not. An asynchronous
socket triggers events in notification of network events. A non-
asynchronous socket has operations which block while waiting for
network events.
- Returns:
-
true
if the socket is asynchronous,
false
if it is non-asynchronous.
- See Also:
- setAsynchronous, setRemoteHostName, connect
setAsynchronous
public synchronized void setAsynchronous(boolean value)
- Sets the mode of the socket to asynchronous or non-asynchronous.
Notes:
The socket must be created before setting this property.
If not, the LastError property is set to SockENotCreated.
- Parameters:
- value - If
true
, the socket is set to be
asynchronous. If false
, the socket is set to be
non-asynchronous.
- See Also:
- getAsynchronous
getLastError
public int getLastError()
- Gets the error code of the last operation on the socket that failed.
- Returns:
- The error code of the last operation on the socket that
failed.
- See Also:
- SocketExceptionCode
getLocalHostAddress
public static byte[] getLocalHostAddress()
- Gets the internet address of the local host for the socket.
Notes:
If the local host is unknown, null
is returned and
the LastError property is set to SockEUnknownHost.
- Returns:
- The internet IP address as an array of bytes, with the highest-
order byte as the first element of the array.
- See Also:
- SocketExceptionCode, getLocalHostName
getLocalHostName
public static String getLocalHostName()
- Gets the name of the local host for the socket.
Notes:
If the local host is unknown, null
is returned and
the LastError property is set to SockEUnknownHost.
- Returns:
- The name of the local host.
- See Also:
- SocketExceptionCode, getLocalHostAddress
getLocalPort
public int getLocalPort()
- Gets the local port used by the socket.
Notes:
The socket must be created before getting this property.
If not, the LastError property is set to SockENotCreated.
A connection-based socket should not set the local port.
Rather, the local port is determined at connection time.
- Returns:
- The local port number in use by the socket.
- See Also:
- SocketExceptionCode, setLocalPort
setLocalPort
public synchronized void setLocalPort(int port)
- Sets the local port to be used by the socket.
Notes:
The socket must be created before setting this property.
If not, the LastError property is set to SockENotCreated.
If the local port is not set, or set to 0, then a free port
is assigned by the system.
- Parameters:
- port - The local port number to be used by the socket.
- See Also:
- SocketExceptionCode, getLocalPort
getRemoteHostName
public String getRemoteHostName()
- Gets the name of the remote host for a connected stream socket.
Notes:
The socket must be created before getting this property.
If not, the LastError property is set to SockENotCreated.
If the remote host is unknown, null
is returned.
- Returns:
- The name of the remote host to which the socket is connected.
- See Also:
- SocketExceptionCode, setRemoteHostName
setRemoteHostName
public synchronized void setRemoteHostName(String name)
- Sets the name of the remote host in preparation of a connect
operation on a stream socket.
Notes:
The socket must be created before setting this property.
If not, the LastError property is set to SockENotCreated.
If the socket is non-asynchronous, this method blocks
while the remote host name is resolved.
If the socket is asynchronous, this method returns immediately,
however, getRemoteHostName will not return the correct name until the
SocketHostResolved event has been triggered.
If the remote host cannot be resolved, the RemoteHostName property
is set to null
is and the LastError property is set to
SockEUnknownHost.
- Parameters:
- name - The name of the remote host to which the socket is
to be connected.
- See Also:
- SocketExceptionCode, getRemoteHostName, connect
getRemoteInetAddress
public byte[] getRemoteInetAddress()
- Gets the internet address of the remote host for a connected stream
socket.
Notes:
The socket must be created before getting this property.
If not, the LastError property is set to SockENotCreated and
null
is returned.
If the remote host has not been set, the LastError property is set
to SockERemoteHostNotSet and null
is returned.
- Returns:
- The internet IP address of the remote host as an array of bytes,
with the highest-order byte as the first element of the array.
- See Also:
- SocketExceptionCode, getRemoteHostName
getRemotePort
public int getRemotePort()
- Gets the port of the remote host for a connected stream socket.
Notes:
The socket must be created before getting this property.
If not, the LastError property is set to SockENotCreated and 0
is returned.
A server socket should not set the remote port.
Rather, the remote port is determined upon a call to accept.
- Returns:
- The port of the remote host to which the socket is connected.
- See Also:
- SocketExceptionCode, setRemotePort
setRemotePort
public synchronized void setRemotePort(int port)
- Sets the port of the remote host in preparation of a connect
operation on a stream socket.
Notes:
The socket must be created before setting this property.
If not, the LastError property is set to SockENotCreated.
Setting this property on a socket that is already connected
will cause the socket to be closed, then re-connected.
- Parameters:
- port - the port of the remote host to which the socket is
to be connected.
- See Also:
- SocketExceptionCode, getRemotePort, connect
resetLastError
public synchronized void resetLastError()
- Resets the error code of the last operation on the socket that failed
to SockENoError.
- See Also:
- SocketExceptionCode
close
public abstract boolean close()
- Closes the socket.
ResetLocalPort
protected abstract boolean ResetLocalPort(int port)
ResetRemotePort
protected abstract boolean ResetRemotePort(int port)
ResetAsynchronous
protected abstract boolean ResetAsynchronous(boolean value)
RaiseError
protected void RaiseError(byte error)
RaiseError
protected void RaiseError(byte error,
Exception exception)
All Packages Class Hierarchy This Package Previous Next Index