sys::Obj inet::TcpSocket
public class TcpSocket
[javaPeer]
TcpSocket models a bi-directional TCP stream. Client side sockets are opened using TcpSocket.connect(). Server side sockets opened via TcpServerSocket.bind() and accept(). The Sedona socket APIs are all asynchronous to be used in a single threaded environment.
public static const define int READ
Bitmask for select when socket is readable
public static const define int WRITE
Bitmask for select when socket is writable
public native void close()
Shutdown and close this socket.
public native bool connect(IpAddr addr, int port)
Connect this socket to the specified IP address and port. This method is non-blocking. Poll the socket using finishConnect() to determine when the connection been completed (either successfully or not). Return false if there is an immediate failure, or true if this call succeeds.
public native bool finishConnect()
Poll the socket to see if the connection has completed. Return false if the connection is still in-progress. If the connection attempt has completed then return true and check isClosed() for success.
- Pending: return false - Success: return true, closed=false - Failed: return true, closed=true
In the case that the state after a finishConnect() call is Failed, you must still call close() to properly free the socket that was opened in the connect() call.
public bool isClosed()
Is this socket closed.
public native int read(byte[] b, int off, int len)
Receive the specified bytes from the socket. Return the number of bytes actually read which may be equal to or less than len. If the connection is terminated or there is any other error close the socket and return -1.
public native int write(byte[] b, int off, int len)
Send the specified bytes over the socket. Return the number of bytes actually written which may be equal to or less than len. If the connection is terminated or there is any other error close the socket and return -1.