TCPListener¶
Listens for new network connections.
The following program creates an echo server that listens for connections on port 8989 and echoes back any data it receives.
use "net"
class MyTCPConnectionNotify is TCPConnectionNotify
fun ref received(
conn: TCPConnection ref,
data: Array[U8] iso,
times: USize)
: Bool
=>
conn.write(String.from_array(consume data))
true
fun ref connect_failed(conn: TCPConnection ref) =>
None
class MyTCPListenNotify is TCPListenNotify
fun ref connected(listen: TCPListener ref): TCPConnectionNotify iso^ =>
MyTCPConnectionNotify
fun ref not_listening(listen: TCPListener ref) =>
None
actor Main
new create(env: Env) =>
TCPListener(TCPListenAuth(env.root),
recover MyTCPListenNotify end, "", "8989")
Implements¶
- AsioEventNotify tag
Constructors¶
create¶
Listens for both IPv4 and IPv6 connections.
new tag create(
auth: TCPListenAuth val,
notify: TCPListenNotify iso,
host: String val = "",
service: String val = "0",
limit: USize val = 0,
read_buffer_size: USize val = 16384,
yield_after_reading: USize val = 16384,
yield_after_writing: USize val = 16384)
: TCPListener tag^
Parameters¶
- auth: TCPListenAuth val
- notify: TCPListenNotify iso
- host: String val = ""
- service: String val = "0"
- limit: USize val = 0
- read_buffer_size: USize val = 16384
- yield_after_reading: USize val = 16384
- yield_after_writing: USize val = 16384
Returns¶
- TCPListener tag^
ip4¶
Listens for IPv4 connections.
new tag ip4(
auth: TCPListenAuth val,
notify: TCPListenNotify iso,
host: String val = "",
service: String val = "0",
limit: USize val = 0,
read_buffer_size: USize val = 16384,
yield_after_reading: USize val = 16384,
yield_after_writing: USize val = 16384)
: TCPListener tag^
Parameters¶
- auth: TCPListenAuth val
- notify: TCPListenNotify iso
- host: String val = ""
- service: String val = "0"
- limit: USize val = 0
- read_buffer_size: USize val = 16384
- yield_after_reading: USize val = 16384
- yield_after_writing: USize val = 16384
Returns¶
- TCPListener tag^
ip6¶
Listens for IPv6 connections.
new tag ip6(
auth: TCPListenAuth val,
notify: TCPListenNotify iso,
host: String val = "",
service: String val = "0",
limit: USize val = 0,
read_buffer_size: USize val = 16384,
yield_after_reading: USize val = 16384,
yield_after_writing: USize val = 16384)
: TCPListener tag^
Parameters¶
- auth: TCPListenAuth val
- notify: TCPListenNotify iso
- host: String val = ""
- service: String val = "0"
- limit: USize val = 0
- read_buffer_size: USize val = 16384
- yield_after_reading: USize val = 16384
- yield_after_writing: USize val = 16384
Returns¶
- TCPListener tag^
Public Behaviours¶
set_notify¶
Change the notifier.
Parameters¶
- notify: TCPListenNotify iso
dispose¶
Stop listening.
Public Functions¶
local_address¶
Return the bound IP address.
Returns¶
- NetAddress val
close¶
Dispose of resources.
Returns¶
- None val