forked from covscript/covscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote_display.csp
51 lines (51 loc) · 1.34 KB
/
remote_display.csp
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
package remote_display
import darwin
import network
using network
using iostream
struct client
var sock=new tcp.socket
function connect_local()
sock.connect(tcp.resolve("127.0.0.1","512"))
end
function connect(host)
sock.connect(tcp.resolve(host,"512"))
end
function transfer(pic)
pic.save_to_file("client_tmp.cdpf")
var fs=fstream("client_tmp.cdpf",openmode.in)
var buff=fs.getline()
sock.send(to_string(buff.size()))
if sock.receive(32)=="READY"
sock.send(buff)
if sock.receive(32)!="FINISH"
throw runtime.exception("Error")
end
else
throw runtime.exception("Error")
end
end
end
struct server
var sock=new tcp.socket
function init_local()
var acceptor=tcp.acceptor(tcp.endpoint("127.0.0.1",512))
sock.accept(acceptor)
end
function init()
var acceptor=tcp.acceptor(tcp.endpoint_v4(512))
sock.accept(acceptor)
end
function transfer(pic)
var length=sock.receive(32).to_number()
sock.send("READY")
var fs=fstream("server_tmp.cdpf",openmode.out)
fs.print(sock.receive(length))
fs.flush()
fs=null
pic.load_from_file("server_tmp.cdpf")
end
function finish()
sock.send("FINISH")
end
end