All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----powersoft.jcm.net.BaseSocket | +----powersoft.jcm.net.Socket
Notes: Instances of DatagramSocket and StreamSocket are not used directly. Instead, the method setType() is used to specify the type of the connection. The implementation keeps a pointer to an instance of the appropriate subclass of Socket and dispatches calls through that pointer.
Example:
// connection-based client stream socket Socket socket = new Socket(); socket.Create( SockSTREAM ); socket.setRemoteHostName( "watcom.com" ); socket.setRemotePort( 1 ); if ( socket.connect() ) { socket.send( "Hello!" ); } // connection-based client datagram socket Socket socket = new Socket(); socket.Create( SockDGRAM ); socket.setRemoteHostName( "watcom.com" ); socket.setRemotePort( 1 ); if ( socket.connect() ) { socket.send( "Hello!" ); } // non-connection-based client datagram socket Socket socket = new Socket(); socket.Create( SockDGRAM ); socket.setRemoteHostName( "watcom.com" ); socket.setRemotePort( 1 ); socket.send( "Hello!" );
public final static byte SockUNKNOWN
public final static byte SockSTREAM
public final static byte SockDGRAM
public Socket()
protected Socket(Socket socket)
protected void finalize()
public synchronized void addSocketConnectListener(SocketConnectListener l)
public synchronized EventListenerVector getSocketConnectListeners()
public synchronized void handleSocketConnect(SocketConnectEvent data)
public synchronized void removeSocketConnectListener(SocketConnectListener l)
public synchronized void addSocketSendCompleteListener(SocketSendCompleteListener l)
public synchronized EventListenerVector getSocketSendCompleteListeners()
public synchronized void handleSocketSendComplete(SocketSendCompleteEvent data)
public synchronized void removeSocketSendCompleteListener(SocketSendCompleteListener l)
public synchronized void addSocketDataArrivalListener(SocketDataArrivalListener l)
public synchronized EventListenerVector getSocketDataArrivalListeners()
public synchronized void handleSocketDataArrival(SocketDataArrivalEvent data)
public synchronized void removeSocketDataArrivalListener(SocketDataArrivalListener l)
public int getBytesWaiting()
Notes: The socket must be created before getting this property. If not, the LastError property is set to SockENotCreated and -1 is returned.
public byte getType()
Notes: The socket must be created before getting this property. If not, the LastError property is set to SockENotCreated and SockUNKNOWN is returned.
public synchronized void setType(byte type)
Notes: The socket must be created before setting this property. If not, the LastError property is set to SockENotCreated.
public synchronized boolean create(byte type)
Notes:
The socket must not be created before calling this method.
If not, the LastError property is set to SockEIsCreated and
false
is returned.
true
if and only if the socket was successfully
created.
public synchronized boolean connect()
Notes:
The socket must be created before calling this method.
If not, the LastError property is set to SockENotCreated and
false
is returned.
The socket must not be connected before calling this method.
If not, the LastError property is set to SockEIsConnected and
false
is returned.
If the socket is non-asynchronous, this method blocks while the connection is made.
If the socket is asynchronous, this method returns immediately, however, the socket is not connected until the SocketConnect event has been triggered.
If a connection has been made on a datagram socket, a new connection-based stream socket is created.
true
if the socket is non-asynchronous and the
connection was successful, or if the socket is asynchronous
and the connection attempt was sucessfully started.
public synchronized boolean send(byte buffer[])
Notes:
The socket must be created before calling this method.
If not, the LastError property is set to SockENotCreated and
false
is returned.
If the socket is of type SockSTREAM, then it
must be connected before calling this method.
If not, the LastError property is set to SockENotConnected and
false
is returned.
If the socket is non-asynchronous, this method blocks while the send is in progress.
If the socket is asynchronous, this method returns immediately, however, the data transfer to the network is not complete until the SocketSendComplete event has been triggered.
If a connection has been made on a datagram socket, a new connection-based stream socket is created.
true
if the socket is non-asynchronous and the
send was successful, or if the socket is asynchronous
and the send attempt was sucessfully started.
public synchronized boolean send(byte buffer[], int length)
Notes:
The socket must be created before calling this method.
If not, the LastError property is set to SockENotCreated and
false
is returned.
If the socket is of type SockSTREAM, then it
must be connected before calling this method.
If not, the LastError property is set to SockENotConnected and
false
is returned.
If the socket is non-asynchronous, this method blocks while the send is in progress.
If the socket is asynchronous, this method returns immediately, however, the data transfer to the network is not complete until the SocketSendComplete event has been triggered.
If a connection has been made on a datagram socket, a new connection-based stream socket is created.
true
if the socket is non-asynchronous and the
send was successful, or if the socket is asynchronous
and the send attempt was sucessfully started.
public synchronized int receive(byte buffer[])
Notes: The socket must be created before calling this method. If not, the LastError property is set to SockENotCreated and -1 is returned.
If the socket is of type SockSTREAM, then it must be connected before calling this method. If not, the LastError property is set to SockENotConnected and -1 is returned.
If the socket is non-asynchronous, and the length of the buffer is greater than the number of bytes waiting, this method blocks while the receive is in progress.
If the socket is asynchronous, this method should only be called in response to a SocketDataArrival event, and only the number of bytes waiting should be received (to prevent blocking).
public synchronized int receive(byte buffer[], int length)
Notes: The socket must be created before calling this method. If not, the LastError property is set to SockENotCreated and -1 is returned.
If the socket is of type SockSTREAM, then it must be connected before calling this method. If not, the LastError property is set to SockENotConnected and -1 is returned.
If the socket is non-asynchronous, and the length of the buffer is greater than the number of bytes waiting, this method blocks while the receive is in progress.
If the socket is asynchronous, this method should only be called in response to a SocketDataArrival event, and only the number of bytes waiting should be received (to prevent blocking).
public boolean close()
Notes:
The socket must be created before calling this method.
If not, the LastError property is set to SockENotCreated and
false
is returned.
true
if the connection was successfully closed.
public String toString()
protected boolean IsStream()
protected boolean ResetLocalPort(int port)
protected boolean ResetRemotePort(int port)
protected boolean ResetAsynchronous(boolean value)
All Packages Class Hierarchy This Package Previous Next Index