Wrapper around java.nio.channels for non-blocking network I/O.
Channels are stateful. Functions that mutate channel state use the ! suffix convention.
Wrapper around java.nio.channels for non-blocking network I/O. Channels are stateful. Functions that mutate channel state use the ! suffix convention.
(accept! ch)Accepts an incoming connection on ch.
In blocking mode: blocks until a connection arrives and returns the new SocketChannel.
In non-blocking mode: returns the new SocketChannel immediately, or nil if no connection is pending.
Accepts an incoming connection on `ch`. In blocking mode: blocks until a connection arrives and returns the new SocketChannel. In non-blocking mode: returns the new SocketChannel immediately, or nil if no connection is pending.
(bind! ch addr)(bind! ch addr backlog)Binds ch to addr (an InetSocketAddress).
For ServerSocketChannel, accepts an optional backlog — the maximum
number of pending connections. Defaults to 0 (system default).
Binds `ch` to `addr` (an InetSocketAddress). For ServerSocketChannel, accepts an optional `backlog` — the maximum number of pending connections. Defaults to 0 (system default).
(blocking? ch)Returns true if ch is in blocking mode.
Returns true if `ch` is in blocking mode.
(configure-blocking! ch blocking)Sets the blocking mode of ch. Pass false for non-blocking I/O.
Returns ch.
Sets the blocking mode of `ch`. Pass false for non-blocking I/O. Returns `ch`.
(connect! ch addr)Connects ch to addr (an InetSocketAddress).
In blocking mode: blocks until the connection is established and returns true.
In non-blocking mode: initiates the connection and returns false if it cannot be completed immediately. Call finish-connect! later to complete it (typically after a Selector signals OP_CONNECT).
Connects `ch` to `addr` (an InetSocketAddress). In blocking mode: blocks until the connection is established and returns true. In non-blocking mode: initiates the connection and returns false if it cannot be completed immediately. Call finish-connect! later to complete it (typically after a Selector signals OP_CONNECT).
(connected? ch)Returns true if ch has an established connection.
Returns true if `ch` has an established connection.
(connection-pending? ch)Returns true if a non-blocking connect! has been initiated on ch
but not yet completed via finish-connect!.
Returns true if a non-blocking connect! has been initiated on `ch` but not yet completed via finish-connect!.
(datagram-bind! ch addr)Binds ch (a DatagramChannel) to addr (an InetSocketAddress).
Pass (inet-address port) with no host to bind to the wildcard address.
Binds `ch` (a DatagramChannel) to `addr` (an InetSocketAddress). Pass (inet-address port) with no host to bind to the wildcard address.
(datagram-channel)Opens and returns a new DatagramChannel in blocking mode.
Opens and returns a new DatagramChannel in blocking mode.
(datagram-connect! ch addr)Connects ch (a DatagramChannel) to addr.
This is optional and restricts the channel to only send/receive
datagrams from that address. Not required for general UDP usage.
Connects `ch` (a DatagramChannel) to `addr`. This is optional and restricts the channel to only send/receive datagrams from that address. Not required for general UDP usage.
(datagram-connected? ch)Returns true if ch (a DatagramChannel) is connected to a specific
remote address.
Returns true if `ch` (a DatagramChannel) is connected to a specific remote address.
(disconnect! ch)Disconnects ch (a DatagramChannel) from its connected address,
if any. Safe to call on an unconnected channel. Returns ch.
Disconnects `ch` (a DatagramChannel) from its connected address, if any. Safe to call on an unconnected channel. Returns `ch`.
(finish-connect! ch)Completes a non-blocking connection initiated by connect!. Returns true if the connection is now established, false if it is still in progress.
Completes a non-blocking connection initiated by connect!. Returns true if the connection is now established, false if it is still in progress.
(get-option ch option)Gets the current value of a socket option on ch.
Gets the current value of a socket option on `ch`.
(inet-address port)(inet-address host port)Constructs an InetSocketAddress from host (String) and port (int).
With arity-1, constructs a wildcard address bound to port.
Constructs an InetSocketAddress from `host` (String) and `port` (int). With arity-1, constructs a wildcard address bound to `port`.
(local-address ch)Returns the local SocketAddress bound to ch, or nil if unbound.
Returns the local SocketAddress bound to `ch`, or nil if unbound.
(remote-address ch)Returns the remote SocketAddress connected to ch, or nil if
the channel is not connected.
Returns the remote SocketAddress connected to `ch`, or nil if the channel is not connected.
(server-socket-channel)Opens and returns a new ServerSocketChannel in blocking mode.
Opens and returns a new ServerSocketChannel in blocking mode.
(set-option! ch option value)Sets a socket option on ch. option should be a constant from
java.net.StandardSocketOptions e.g. StandardSocketOptions/TCP_NODELAY.
Returns ch.
Sets a socket option on `ch`. `option` should be a constant from java.net.StandardSocketOptions e.g. StandardSocketOptions/TCP_NODELAY. Returns `ch`.
(shutdown-input! ch)Shuts down the read half of ch without closing the channel.
Subsequent reads will return -1 (EOF). The write half remains open.
Returns ch.
Throws NotYetConnectedException if the channel is not connected.
Shuts down the read half of `ch` without closing the channel. Subsequent reads will return -1 (EOF). The write half remains open. Returns `ch`. Throws NotYetConnectedException if the channel is not connected.
(shutdown-output! ch)Shuts down the write half of ch without closing the channel.
Subsequent writes will throw ClosedChannelException. The read half
remains open, allowing any in-flight data from the remote end to
still be received. Returns ch.
Throws NotYetConnectedException if the channel is not connected.
Shuts down the write half of `ch` without closing the channel. Subsequent writes will throw ClosedChannelException. The read half remains open, allowing any in-flight data from the remote end to still be received. Returns `ch`. Throws NotYetConnectedException if the channel is not connected.
(socket-channel)(socket-channel addr)Opens and returns a new SocketChannel in blocking mode.
With arity-1, opens and immediately connects to addr.
Opens and returns a new SocketChannel in blocking mode. With arity-1, opens and immediately connects to `addr`.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |