Skip to content

Instantly share code, notes, and snippets.

@waratuman
Created March 18, 2017 00:15
Show Gist options
  • Save waratuman/308b7890de35efe9027cc965fcbf0a0d to your computer and use it in GitHub Desktop.
Save waratuman/308b7890de35efe9027cc965fcbf0a0d to your computer and use it in GitHub Desktop.
use "net"
actor Main
let _userList: PcUser tag = PcUser
new create(env: Env) =>
try
TCPListener(
env.root as AmbientAuth,
PcNetTcpListenNotifier(_userList),
"",
"8080"
)
end
actor PcUser
let _userList: Array[String] ref = Array[String]
be add(userName: String) =>
_userList.push(userName)
be writeSize(conn: TCPConnection tag) =>
conn.write(_userList.size().string())
class PcNetTcpListenNotifier is TCPListenNotify
var _user: PcUser tag
new iso create(user: PcUser tag) =>
_user = user
fun ref connected(listen: TCPListener ref): TCPConnectionNotify iso^ =>
PcNetTcpConnectionNotifier(_user)
class PcNetTcpConnectionNotifier is TCPConnectionNotify
var _user: PcUser tag
new iso create(user: PcUser tag) =>
_user = user
fun ref received(conn: TCPConnection ref, data: Array[U8] iso): Bool =>
_user.add("abc")
_user.writeSize(conn)
false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment