aboutsummaryrefslogtreecommitdiff
path: root/bin/client/main.lua
blob: df33e21659d3c46e07e3654629bc77be96b307c7 (plain)
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
io.stdout:setvbuf("no")
local thread = nil 
local socket = nil
local asynReceive = [[
io.stdout:setvbuf("no")
local thread = jin.thread.getThread() 
local socket = thread:demand(1)
while true do 
	-- local sendBuf = thread:demand(3)
	-- socket:send(sendBuf)
	local buf = socket:receive() 
	thread:send(2, buf)
end 
]]
local x = 30
local y = 30
jin.core.onLoad = function() 
	thread = jin.thread.Thread("asynReceive", asynReceive)
	jin.net.init()
	socket = jin.net.Socket("TCP", "127.0.0.1", 8809)
	thread:start()
	thread:send(1, socket)
end 

jin.core.onEvent = function(e)
	if e.type == "quit" then
		jin.core.stop()	elseif e.type == "keydown" then 
		if e.key == "Escape" then 
			jin.core.stop()
		end 
	end 
end 
local i = 0
jin.core.onUpdate = function(dt) 
	if thread:receive(2) then 
		local buf = thread:fetch(2)
		x, xl = buf:grabFloat(0)
		y, yl = buf:grabFloat(xl)
	end 

	-- local buf = jin.net.Buffer(0)
	-- buf:append(x)
	-- buf:append(y)
	-- thread:send(3, buf)
end 

jin.core.onDraw = function() 
	jin.graphics.circle("fill", x, y, 12)
end