-
Notifications
You must be signed in to change notification settings - Fork 71
/
class_RemoteObj.ahk
61 lines (53 loc) · 1.2 KB
/
class_RemoteObj.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class RemoteObj
{
__New(Obj, Address)
{
this.Obj := Obj
this.Server := new SocketTCP()
this.Server.OnAccept := this.OnAccept.Bind(this)
this.Server.Bind(Address)
this.Server.Listen()
}
OnAccept(Server)
{
Sock := Server.Accept()
Text := Sock.RecvLine()
Query := Jxon_Load(Text)
if (Query.Action == "__Get")
RetVal := this.Obj[Query.Key]
else if (Query.Action == "__Set")
RetVal := this.Obj[Query.Key] := Query.Value
else if (Query.Action == "__Call")
RetVal := this.Obj[Query.Name].Call(this.Obj, Query.Params*)
Sock.SendText(Jxon_Dump({"RetVal": RetVal}) "`r`n")
Sock.Disconnect()
}
}
class RemoteObjClient
{
__New(Addr)
{
ObjRawSet(this, "__Addr", Addr)
}
__Get(Key)
{
return RemoteObjSend(this.__Addr, {"Action": "__Get", "Key": Key})
}
__Set(Key, Value)
{
return RemoteObjSend(this.__Addr, {"Action": "__Set", "Key": Key, "Value": Value})
}
__Call(Name, Params*)
{
return RemoteObjSend(this.__Addr, {"Action": "__Call", "Name": Name, "Params": Params})
}
}
RemoteObjSend(Addr, Obj)
{
Sock := new SocketTCP()
Sock.Connect(Addr)
Sock.SendText(Jxon_Dump(Obj) "`r`n")
RetVal := Jxon_Load(Sock.RecvLine()).RetVal
Sock.Disconnect()
return RetVal
}