-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMainScene.lua
More file actions
29 lines (24 loc) · 844 Bytes
/
Copy pathMainScene.lua
File metadata and controls
29 lines (24 loc) · 844 Bytes
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
local socketTcp = require('app.views.SocketTCP')
local MainScene = class("MainScene", cc.load("mvc").ViewBase)
function MainScene:onCreate()
-- add background image
display.newSprite("HelloWorld.png")
:move(display.center)
:addTo(self)
-- add HelloWorld label
cc.Label:createWithSystemFont("Hello World", "Arial", 40)
:move(display.cx, display.cy + 200)
:addTo(self)
self:setPosition1(100, 100)
local s = socketTcp.new('127.0.0.1', 17642)
s:connect()
local function onConnected(event)
s:send('test it')
end
local function onData(__event)
print("socket status: %s, partial:%s", __event.name, __event.data)
end
s:addEventListener(socketTcp.EVENT_CONNECTED, onConnected)
s:addEventListener(socketTcp.EVENT_DATA, onData)
end
return MainScene