#include "hspsock.as"
#define ADDR "127.0.0.1"
#define PORT 27182
#define BUFSIZE 256
sdim send, BUFSIZE
sdim recv, BUFSIZE
onexit *exit
button "SERVER", *sb
button "CLIENT", *cb
stop
*sb
clrobj
pos 0, 0
mes "SERVER MODE"
*s
mes
sockmake 0, PORT
if stat != 0 : ec = 1 : goto *se
repeat
sockwait 0
if stat != 1 : break
wait 10
loop
if stat != 0 : ec = 2 : goto *se
send = strf("I'M A SERVER! @ %02d:%02d:%02d.%03d", gettime(4), gettime(5), gettime(6), gettime(7))
sockput send, 0
if stat != 0 : ec = 3 : goto *se
mes "SEND: " + send
repeat
sockcheck 0
if stat != 1 : break
wait 10
loop
if stat != 0 : ec = 4 : goto *se
sockget recv, BUFSIZE, 0
if stat != 0 : ec = 5 : goto *se
mes "RECV: " + recv
sockclose 0
goto *s
*cb
mes
objenable 1, 0
clrobj 0, 0
sockopen 0, ADDR, PORT
if stat != 0 : ec = 1 : goto *ce
repeat
sockcheck 0
if stat != 1 : break
wait 10
loop
if stat != 0 : ec = 2 : goto *ce
sockget recv, BUFSIZE, 0
if stat != 0 : ec = 3 : goto *ce
mes "RECV: " + recv
send = strf("I'M A CLIENT! @ %02d:%02d:%02d.%03d", gettime(4), gettime(5), gettime(6), gettime(7))
sockput send, 0
if stat != 0 : ec = 4 : goto *ce
mes "SEND: " + send
sockclose 0
objenable 1, 1
stop
*se
dialog "SERVER ERROR #"+ec, 1
goto *exit
*ce
dialog "CLIENT ERROR #"+ec, 1
goto *exit
*exit
sockclose 0
end
I2luY2x1ZGUgImhzcHNvY2suYXMiCgojZGVmaW5lIEFERFIgIjEyNy4wLjAuMSIKI2RlZmluZSBQT1JUIDI3MTgyCiNkZWZpbmUgQlVGU0laRSAyNTYKCglzZGltIHNlbmQsIEJVRlNJWkUKCXNkaW0gcmVjdiwgQlVGU0laRQoJCglvbmV4aXQgKmV4aXQKCQoJYnV0dG9uICJTRVJWRVIiLCAqc2IKCWJ1dHRvbiAiQ0xJRU5UIiw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