public static void main (String [] argv) throws

may still be in transit. For this reason, it’s rarely a good design choice to have multiple, noncooperating threads share the same side of a stream socket. The connect() and finishConnect() methods are mutually synchronized, and any read or write calls will block while one of these operations is in progress, even in nonblocking mode. Test the connection state with isConnected() if there’s any doubt or if you can’t afford to let a read or write block on a channel in this circumstance. 3.5.4 DatagramChannel The last of the socket channels is DatagramChannel. Like SocketChannel with Socket and ServerSocketChannel with ServerSocket, every DatagramChannel object has an associated DatagramSocket object. The naming pattern doesn’t quite hold here: “DatagramSocketChannel” is a bit unwieldy, so “DatagramChannel” was chosen instead. Just as SocketChannel models connection-oriented stream protocols such as TCP/IP, DatagramChannel models connectionless packet-oriented protocols such as UDP/IP: public abstract class DatagramChannel extends AbstractSelectableChannel implements ByteChannel, ScatteringByteChannel, GatheringByteChannel { // This is a partial API listing public static DatagramChannel open() throws IOException public abstract DatagramSocket socket(); public abstract DatagramChannel connect (SocketAddress remote) throws IOException; public abstract boolean isConnected(); public abstract DatagramChannel disconnect() throws IOException; public abstract SocketAddress receive (ByteBuffer dst) throws IOException; public abstract int send (ByteBuffer src, SocketAddress target) public abstract int read (ByteBuffer dst) throws IOException; public abstract long read (ByteBuffer [] dsts) throws IOException; public abstract long read (ByteBuffer [] dsts, int offset, int length) throws IOException; public abstract int write (ByteBuffer src) throws IOException; public abstract long write(ByteBuffer[] srcs) throws IOException; public abstract long write(ByteBuffer[] srcs, int offset, int length) throws IOException; } The creation pattern is the same for DatagramChannel as for the other socket channels: invoke the static open() method to create a new instance. The new DatagramChannel will 111
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services

Comments are closed.