|
For the latest stable version, please use Emilua API 0.11! |
ip.udp.socket
local sock = ip.udp.socket.new()
sock.open('v4')
sock:bind(ip.address.any_v4(), 1234)
local buf = byte_span.new(1024)
local nread, remote_addr, remote_port = sock:receive_from(buf)
sock:send_to(buf:slice(1, nread), remote_addr, remote_port)
Functions
open(self, address_family: "v4"|"v6"|ip.address)
Open the socket.
address_family can be either "v4" or "v6". If you provide an ip.address
object, the appropriate value will be inferred.
shutdown(self, what: "receive"|"send"|"both")
Disable sends or receives on the socket.
what can be one of the following:
"receive"-
Shutdown the receive side of the socket.
"send"-
Shutdown the send side of the socket.
"both"-
Shutdown both send and receive on the socket.
| Doing this only mutates the socket object, but nothing will be sent over the wire. It could be useful if you’re planning to send the FD around to other processes. |
connect(self, addr: ip.address, port: integer)
Set the default destination address so datagrams can be sent using send()
without specifying a destination address.
disconnect(self)
Dissolve the socket’s association by resetting the socket’s peer address
(i.e. connect(3) will be called with an AF_UNSPEC address).
close(self)
Close the socket.
Forward the call to the function with same name in Boost.Asio:
Any asynchronous send, receive or connect operations will be cancelled immediately, and will complete with the
boost::asio::error::operation_abortederror.
cancel(self)
Cancel all asynchronous operations associated with the acceptor.
Forward the call to the function with same name in Boost.Asio:
This function causes all outstanding asynchronous connect, send and receive operations to finish immediately, and the handlers for cancelled operations will be passed the
boost::asio::error::operation_abortederror.
assign(self, address_family: "v4"|"v6"|ip.address, fd: file_descriptor)
Assign an existing native socket to self.
address_family can be either "v4" or "v6". If you provide an ip.address
object, the appropriate value will be inferred.
release(self) → file_descriptor
Release ownership of the native descriptor implementation.
Forward the call to the function with same name in Boost.Asio:
This function causes all outstanding asynchronous connect, send and receive operations to finish immediately, and the handlers for cancelled operations will be passed the
boost::asio::error::operation_abortederror. Ownership of the native socket is then transferred to the caller.
receive(self, buffer: byte_span[, flags: integer]) → integer
Receive a datagram and blocks current fiber until it completes or errs.
Returns the number of bytes read.
flags is 0 or an or-combination of values from
ip.message_flag(3em).
receive_from(self, buffer: byte_span[, flags: integer]) → integer, ip.address, integer
Receive a datagram and blocks current fiber until it completes or errs.
Returns the number of bytes read plus the endpoint (address + port) of the remote sender of the datagram.
flags is 0 or an or-combination of values from
ip.message_flag(3em).
send(self, buffer: byte_span[, flags: integer]) → integer
Send data on the datagram socket and blocks current fiber until it completes or errs.
Returns the number of bytes written.
flags is 0 or an or-combination of values from
ip.message_flag(3em).
The send operation can only be used with a connected socket. Use the
send_to function to send data on an unconnected datagram socket.
|
send_to(self, buffer: byte_span, remote_addr: ip.address, remote_port: integer[, flags: integer]) → integer
Send a datagram to the specified remote endpoint and blocks current fiber until it completes or errs.
Returns the number of bytes written.
flags is 0 or an or-combination of values from
ip.message_flag(3em).
set_option(self, opt: string, val)
Set an option on the socket.
Currently available options are:
"debug""broadcast""do_not_route""send_buffer_size""receive_buffer_size""reuse_address""multicast_loop""multicast_hops""join_multicast_group""leave_multicast_group""multicast_interface""unicast_hops""v6_only"