-
Notifications
You must be signed in to change notification settings - Fork 298
/
ClientServerUnixPath.io
executable file
·52 lines (45 loc) · 1.1 KB
/
ClientServerUnixPath.io
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
#!/usr/bin/env io
socketPath := "/tmp/.io_upsocket"
File with(socketPath) remove
Server := Object clone do(
socket := Socket clone setPath(socketPath)
start := method(
writeln("server listing on path ", socket path)
socket serverOpen
socket setReadTimeout(1)
s := nil
while (s == nil,
write("serverWaitForConnection\n")
s := socket serverWaitForConnection
)
writeln("server got connection ")
s write("HELLO")
wait(0.1)
s read
msg := s readBuffer asString
if (msg == "GOODBYE", writeln("server got GOODBYE"), writeln("message failed"))
wait(0.1)
s close
socket close
Lobby @doMessage(System exit)
wait(0.1)
)
)
Server @start
Client := Object clone do(
socket := Socket clone setPath(socketPath)
start := method(
writeln("client connecting to ", socket path)
wait(2)
socket connect
if (socket isOpen, writeln("client connected"), writeln("connection failed"))
wait(0.1)
socket read
msg := socket readBuffer asString
if (msg == "HELLO", writeln("client got HELLO"), writeln("message failed"))
socket write("GOODBYE")
socket close
)
)
Client @start
loop(wait(1))