xen::net
Provides utitlies for networking and web services.
include net;
Public Classes
TcpStream
Provides facilities for communicating with a TcpListener session. Typically created and returned by accepted TCP connections via TcpListener.
var conn = new net.TcpStream(remote_addr, remote_port);
Public Properties
- remote_addr:
number- The remote IPv4 address of the remote host the stream is currently connected to - remote_port:
number- The port of the remote host the stream is currently connected through
Private Properties
- _fd:
number- Socket file descriptor for current connection
Public Methods
read
read (max_bytes = 4096) -> string | null
Read up to max_bytes from stream.
write
write (data) -> number
Write data to stream.
send
send (data) -> number
Alias for write.
recv
recv (max_bytes = 4096) -> string | null
Alias for read.
close
close () -> null
Close the connection.
shutdown
shutdown (method: number) -> null
Shutdown the connection. The method can be one of three values:
0: read1: write2: both
TcpListener
Binds a specified port and listens to incoming TCP connections on that port. Can receive a TcpStream instance from connections, allowing the ability to read and write data between the host (TcpListener) and client (TcpStream).
var listener = new net.TcpListener(port);
Public Properties
- port:
number- The port to bind to
Private Properties
- _socket:
number- The bound socket file descriptor
Public Methods
bind
bind () -> bool
Bind the socket to the instance port.
listen
listen () -> bool
Begin listening to incoming traffic.
bind_and_listen
bind_and_listen () -> bool
Combines the previous two methods into one.
accept
accept () -> TcpStream | null
Waits on incoming connections and accepts the first one, returning a TcpStream instance.
close
close () -> null
Closes the connection, terminating any active connections with clients.