sockets.datagram.socket

-receive

multimethod

behaviour

create

(create)(create arg)(create port local-addr)

A constructor for datagram sockets. This function my take 0, 1, or two args.

  • 0-arity: Constructs a datagram socket and binds it to any available port on the local host machine.
  • 1-arity: If the argument is an instance of the DatagramSocketImpl class, Creates an unbound datagram socket with the specified DatagramSocketImpl. If the argument is an integer, it is interpreted as a port, in which case, datagram socket will be constructed and bound to the specified port on the local host machine. If the argument is an instance of SocketAddress, the constructor creates a datagram socket, bound to the specified local socket address.
  • 2-arity: Creates a datagram socket, bound to the specified port and local InetAddress.

Socket

protocol

members

bind

(bind this addr)

Binds this DatagramSocket to a specific address and port.

bound?

(bound? this)

Returns the binding state of the socket.

broadcast!

(broadcast! this bool)

Enable/disable SO_BROADCAST.

broadcast?

(broadcast? this)

Tests if SO_BROADCAST is enabled.

channel

(channel this)

Returns the unique DatagramChannel object associated with this datagram socket, if any.

close

(close this)

Closes this datagram socket.

closed?

(closed? this)

Returns whether the socket is closed or not.

connect

(connect this addr)(connect this addr port)

For the 1-arity function, connects this socket to a remote socket address (IP address + port number; must be an instance or subclass of SocketAddress). For the 2-arity function, connects the socket to a remote address amd port for this socket (the address must be an instance or subclass of InetAddress).

connected?

(connected? this)

Returns the connection state of the socket.

disconnect

(disconnect this)

Disconnects the socket.

inet-address

(inet-address this)

Returns the address to which this socket is connected.

local-address

(local-address this)

Gets the local address to which the socket is bound.

local-port

(local-port this)

Returns the port number on the local host to which this socket is bound.

local-socket-address

(local-socket-address this)

Returns the address of the endpoint this socket is bound to.

port

(port this)

Returns the port number to which this socket is connected.

receive

(receive this)(receive this packet)

Receives a datagram packet from this socket. Additionally, the Clojure wrapper allows you to pass the packet size instead of the packet itself. If this option is exercised, a packet of the indicated size will be created and returned. Another Clojure wrapper convenience, the 1-arity version of this function, will use the default packet size DEFAULT_PACKET_SIZE and create a packet under the covers with that size.

receive-buffer-size

(receive-buffer-size this)

Get value of the SO_RCVBUF option for thisDatagramSocket, that is the buffer size used by the platform for input on thisDatagramSocket`.

receive-buffer-size!

(receive-buffer-size! this size)

Sets the SO_RCVBUF option to the specified value for this DatagramSocket.

remote-socket-address

(remote-socket-address this)

Returns the address of the endpoint this socket is connected to, or null if it is unconnected.

reuse-address

(reuse-address this)

Tests if SO_REUSEADDR is enabled.

reuse-address!

(reuse-address! this bool)

Enable/disable the SO_REUSEADDR socket option.

send

(send this packet)

Sends a datagram packet from this socket.

send-buffer-size

(send-buffer-size this)

Get value of the SO_SNDBUF option for this DatagramSocket, that is the buffer size used by the platform for output on this DatagramSocket.

send-buffer-size!

(send-buffer-size! this size)

Sets the SO_SNDBUF option to the specified value for this DatagramSocket.

so-timeout

(so-timeout this)

Retrieve setting for SO_TIMEOUT.

so-timeout!

(so-timeout! this timeout)

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.

traffic-class

(traffic-class this)

Gets traffic class or type-of-service in the IP datagram header for packets sent from this DatagramSocket.

traffic-class!

(traffic-class! this class-int)

Sets traffic class or type-of-service octet in the IP datagram header for datagrams sent from this DatagramSocket.