Skip to content

Instantly share code, notes, and snippets.

@thedeemon
Created June 22, 2018 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedeemon/bbeaa06fe6768c7315a638fafee9cd28 to your computer and use it in GitHub Desktop.
Save thedeemon/bbeaa06fe6768c7315a638fafee9cd28 to your computer and use it in GitHub Desktop.
Simple server returning same HTTP answer to all queries.
use "net"
class MyTCPConnectionNotify is TCPConnectionNotify
fun ref received(conn: TCPConnection ref, data: Array[U8] iso, times: USize) : Bool =>
conn.write("HTTP/1.0 200 OK\nContent-Type: text/html; charset=utf-8\n\nOK\n")
conn.dispose()
false
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) =>
env.out.print("hi!")
try
let auth = env.root as AmbientAuth
TCPListener(auth, recover MyTCPListenNotify end, "", "8080")
else
env.out.print("unable to use the network")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment