upd5
This commit is contained in:
@@ -3,11 +3,11 @@ import netio
|
||||
fn main() {
|
||||
// We want to bind a server socket to the all available local addresses,
|
||||
// (both IPv4 and IPv6) so collect the address info entries for it.
|
||||
ai := netio.translate_addr(
|
||||
service: '1081' // The port number for listen.
|
||||
sock_type: netio.sock_stream // Address must support TCP transport.
|
||||
family: netio.af_inet6 // IPv6 support.
|
||||
flags: netio.ai_passive // Passive mode for binding to any address (0.0.0.0, ::).
|
||||
ai := netio.addr_info(
|
||||
service: '1081' // The port number to listen.
|
||||
socktype: netio.sock_stream // Address must support TCP transport.
|
||||
family: netio.af_inet6 // IPv6 support.
|
||||
flags: netio.ai_passive // Passive mode for binding to any address (0.0.0.0, ::).
|
||||
)!
|
||||
|
||||
// Just initialize variables.
|
||||
@@ -17,7 +17,7 @@ fn main() {
|
||||
// Create socket and bind to the first available address.
|
||||
for a in ai {
|
||||
// Create a socket with advertised parameters.
|
||||
socket = netio.Socket.new(a.family, a.sock_type, a.protocol)!
|
||||
socket = netio.Socket.new(a.family, a.socktype, a.protocol)!
|
||||
|
||||
// Set SO_REUSEADDR enabled. It allows a server to bind to a port that
|
||||
// is still in a `TIME-WAIT` state from a previous connection.
|
||||
@@ -49,6 +49,7 @@ fn main() {
|
||||
defer {
|
||||
socket.close() or { panic(err) }
|
||||
}
|
||||
|
||||
// Start listening for incoming connections on socket.
|
||||
socket.listen(10) or {
|
||||
eprintln('LISTEN: ${err}')
|
||||
@@ -70,7 +71,7 @@ fn main() {
|
||||
}
|
||||
|
||||
// Get remote host and port in numeric format.
|
||||
remote_host, remote_port := netio.translate_name(remote_addr,
|
||||
remote_host, remote_port := netio.name_info(remote_addr,
|
||||
flags: netio.ni_numerichost | netio.ni_numericserv
|
||||
)!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user