Class Socket

extends Object implements Socket MulticastSocket

Class summary


constructor network_/Interface hostname/string port/int
Constructs a new UDP socket bound to the given hostname and port.
constructor network/Client

Constructors

constructor network_/Interface hostname/string port/int
Constructs a new UDP socket bound to the given hostname and port.
The hostname is the local address to bind to. For client sockets, pass 0.0.0.0. For server sockets pass 0.0.0.0 to listen on all interfaces, or the address of a particular interface in order to listen on that particular one.
The port can be zero, in which case the system picks a free port.

Statics

multicast network_/Client --port/int=null --if-addr/IpAddress=null --reuse-address/bool=true --reuse-port/bool=false --loopback/bool=true --ttl/int=1 -> Socket
Constructs a multicast UDP socket.
The socket is configured for multicast communication but does not automatically join any group. Call multicast-add-membership to join a group for receiving.
The port is the local port to bind to. If null, the OS picks an ephemeral port (typical for send-only sockets).
The if-addr is the IP address of the interface to use for outgoing multicast (IP_MULTICAST_IF). If null, the OS picks a default.
If reuse-address is true (the default), the SO_REUSEADDR option is set.
If reuse-port is true (not default), the SO_REUSEPORT option is set.
If loopback is true (the default), multicast packets sent from this socket are also delivered to receivers on the same host.
The ttl is the multicast time-to-live (default 1, meaning link-local only).

multicast network_/Client address/IpAddress port/int --if-addr/IpAddress=null --reuse-address/bool=true --reuse-port/bool=false --loopback/bool=true --ttl/int=1 -> Socket
Deprecated. Use the named-args-only constructor (without a positional address) followed by multicast-add-membership instead.
Constructs a multicast UDP socket, binds to port, and automatically joins the multicast group address.

Methods

broadcast= value/bool -> any

close -> none

connect address/SocketAddress -> none

mtu -> int

multicast-ttl= value/int -> any

operator == other/any -> bool
Whether this object is equal to the other.
By default, identical is used for equality.
Inheritance
Classes overwrite this operator to get an equality specific to their needs. Equality operators often compare the type and field contents. For example:

class Pin:
  number/int

  constructor .number:

  operator == other:
    if other is not Pin: return false
    return number == other.number
A class doesn't have to follow the above format, but it must keep the operator in sync with any hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).

read -> any

receive -> any

reuse-address= value/bool -> any

reuse-port= value/bool -> any

send msg/any -> any

Stringifies this object.
Inheritance
Objects that need a human-friendly string representation should overwrite this method. The default string is based on the internal class-ID.

write data/Data from/int=0 to/int=data.byte-size -> any