Skip to content

Instantly share code, notes, and snippets.

@CandleCandle
Last active May 3, 2016 15:38
Show Gist options
  • Save CandleCandle/0b56d4e4a24d1ff6006df47f51304fed to your computer and use it in GitHub Desktop.
Save CandleCandle/0b56d4e4a24d1ff6006df47f51304fed to your computer and use it in GitHub Desktop.
iso vs iso!
use "collections"
use "net"
actor Main
new create(env: Env) =>
let item = Settings.create("localhost", 5554)
let s = ServerRef.create(item)
s.connect(env, Listener.create(s))
actor ServerRef
var _conn: (None | TCPConnection) = None
let _settings: Settings
new create(settings': Settings) =>
_settings = settings'
be connect(env: Env, listener: Listener iso) =>
env.out.print("connecting to " + _settings.host + ":" + _settings.port.string())
try
_conn = TCPConnection.create(
env.root as AmbientAuth,
consume listener,
_settings.host,
_settings.port.string()
)
send("connected\n")
else
env.out.print("Failed to connect to " + _settings.host + ":" + _settings.port.string())
end
be send(msg: String) =>
try (_conn as TCPConnection).write(msg) end
class Listener is TCPConnectionNotify
let _server: ServerRef
new iso create(server': ServerRef) =>
_server = server'
fun ref received(conn: TCPConnection ref, data: Array[U8] iso) =>
send("reply")
fun send(msg: String) =>
_server.send(msg)
class val Settings
let host: String
let port: U16
new val create(host': String, port': U16) =>
host = host'
port = port'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment