Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use "net"
- actor Main
- new create(env: Env) =>
- try
- TCPListener(env.root as AmbientAuth, recover Server end, "", "12345")
- end
- primitive Response
- fun apply(): String =>
- "HTTP/1.1 200 Ok\r\nContent-Length: 11\r\n\r\nHello World"
- class Server is TCPListenNotify
- let _response: String val
- new create() =>
- _response = recover val Response().repeat_str(18 * 1024) end
- fun ref not_listening(self: TCPListener ref) =>
- self.close()
- fun ref connected(self: TCPListener ref): TCPConnectionNotify iso^ =>
- recover Client(_response) end
- class Client is TCPConnectionNotify
- let _response: String val
- new create(response: String val) =>
- _response = response
- fun ref connect_failed(self: TCPConnection ref) =>
- None
- fun ref received(self: TCPConnection ref, data: Array[U8] iso, times: USize): Bool =>
- let requests = String.from_iso_array(consume data).count("\r\n\r\n")
- self.write(_response.trim(Response().size() * requests))
- true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement