| function constructConnection()
			
				    if bConnected == false then
			
				        socket = nil
			
				        socket = net.createConnection(net.TCP, 0)
			
				        socket:on("connection", function(sck, response)
			
				            bConnected = true
			
				            sentCnt = sentCnt + 1
			
				            print("\r\n#### Conneted!\t\t&socket:", socket)
			
				            socket:send(httpPKG)
			
				        end)
			
				        socket:on("disconnection", function(sck, response)
			
				            bConnected = false
			
				            socket:close()
			
				            socket = nil
			
				            print("#### Socket disconneted, @Count=" .. sentCnt ..", Heap=" .. node.heap())
			
				        end)
			
				        socket:on("receive", function(sck, response)
			
				            --print("[Recv] " .. response)
			
				            hh = nil
			
				            curGMT = string.sub(response,string.find(response,"Date: "),string.find(response,"Date: ")+35)
			
				            -- print(curGMT)    -- Date: Sat, 23 Jan 2016 09:10:20 GMT
			
				            hh,mm,ss = string.match(curGMT, "(%d+)%d*:(%d+)%d*:(%d+)%d* GMT")
			
				            if hh ~= nil then
			
				                print("#### Get Internet time from " .. host, (hh+tzone)%24, mm, ss)
			
				                --刚上电需要校准一次,之后仅在半夜12点到1点之间执行校准,这样按钮的次数少
			
				                if (calibratedAfterPowerOn == false) or (hh + tzone == 24) then
			
				                    calibratedAfterPowerOn = true
			
				                    adjustClock(hh+tzone, mm)
			
				                end
			
				            end
			
				        end)
			
				        socket:connect(port, host)
			
				    end
			
				end
			
				-- +++++++++++++++++++++++++++++++
			
				constructConnection()
			
				tmr.alarm(tmrCycled,3660000,1,function() constructConnection() end) 
 
  
 
 (责任编辑:admin)
 |