2014-10-10 92 views
-3

在电晕模拟器和genymotion我可以看到按钮,但在Android设备上我没有看到anythings 并且在控制台中没有错误。 这是main.lua和server.lua,请帮我解决我的问题按钮,在Android设备不apear但在电晕模拟器展示和mobogini

main.lua

local S = {} 
 

 
local socket = require("socket") 
 

 
local clientList = {} 
 
local clientBuffer = {} 
 

 
S.getIP = function() 
 
    local s = socket.udp() 
 
    s:setpeername("74.125.115.104", 80) 
 
    local ip, sock = s:getsockname() 
 
    print("myIP:", ip, sock) 
 
    return ip 
 
end 
 

 
S.createServer = function() 
 

 
    local tcp, err = socket.bind(S.getIP(), 1235) --create a server object 
 
    tcp:settimeout(0) 
 

 
    local function sPulse() 
 
     repeat 
 
      local client = tcp:accept() --allow a new client to connect 
 
      if client then 
 
       print("found client") 
 
       client:settimeout(0) --just check the socket and keep going 
 
       --TO DO: implement a way to check to see if the client has connected previously 
 
       --consider assigning the client a session ID and use it on reconnect. 
 
       clientList[#clientList+1] = client 
 
       clientBuffer[client] = { "hello_client" } --just including something to send below 
 
      end 
 
     until not client 
 
     
 
     local ready, writeReady, err = socket.select(clientList, clientList, 0) 
 
     if err == nil then 
 
      for i = 1, #ready do --list of clients who are available 
 
       local client = ready[i] 
 
       local allData = {} --this holds all lines from a given client 
 

 
       repeat 
 
        local data, err = client:receive() --get a line of data from the client, if any 
 
        --print(data) 
 
        if data then 
 
         allData[#allData+1] = data 
 
        end 
 
       until not data 
 

 
       if (#allData > 0) then --figure out what the client said to the server 
 
        for i, thisData in ipairs(allData) do 
 
         print("thisData: ", thisData) 
 
         --do stuff with data 
 
        end 
 
       end 
 
      end 
 

 
      for sock, buffer in pairs(clientBuffer) do 
 
       for _, msg in pairs(buffer) do --might be empty 
 
        local data, err = sock:send(msg) --send the message to the client 
 
       end 
 
      end 
 
     end 
 
    end 
 

 
    --pulse 10 times per second 
 
    local serverPulse = timer.performWithDelay(100, sPulse, 0) 
 

 
    local function stopServer() 
 
     timer.cancel(serverPulse) --cancel timer 
 
     tcp:close() 
 
     for i, v in pairs(clientList) do 
 
      v:close() 
 
     end 
 
    end 
 
    return stopServer 
 
end 
 

 
return S

server.lua

local S = {} 

local socket = require("socket") 

local clientList = {} 
local clientBuffer = {} 

S.getIP = function() 
    local s = socket.udp() 
    s:setpeername("74.125.115.104", 80) 
    local ip, sock = s:getsockname() 
    print("myIP:", ip, sock) 
    return ip 
end 

S.createServer = function() 

    local tcp, err = socket.bind(S.getIP(), 1235) --create a server object 
    tcp:settimeout(0) 

    local function sPulse() 
     repeat 
      local client = tcp:accept() --allow a new client to connect 
      if client then 
       print("found client") 
       client:settimeout(0) --just check the socket and keep going 
       --TO DO: implement a way to check to see if the client has connected previously 
       --consider assigning the client a session ID and use it on reconnect. 
       clientList[#clientList+1] = client 
       clientBuffer[client] = { "hello_client" } --just including something to send below 
      end 
     until not client 

     local ready, writeReady, err = socket.select(clientList, clientList, 0) 
     if err == nil then 
      for i = 1, #ready do --list of clients who are available 
       local client = ready[i] 
       local allData = {} --this holds all lines from a given client 

       repeat 
        local data, err = client:receive() --get a line of data from the client, if any 
        --print(data) 
        if data then 
         allData[#allData+1] = data 
        end 
       until not data 

       if (#allData > 0) then --figure out what the client said to the server 
        for i, thisData in ipairs(allData) do 
         print("thisData: ", thisData) 
         --do stuff with data 
        end 
       end 
      end 

      for sock, buffer in pairs(clientBuffer) do 
       for _, msg in pairs(buffer) do --might be empty 
        local data, err = sock:send(msg) --send the message to the client 
       end 
      end 
     end 
    end 

    --pulse 10 times per second 
    local serverPulse = timer.performWithDelay(100, sPulse, 0) 

    local function stopServer() 
     timer.cancel(serverPulse) --cancel timer 
     tcp:close() 
     for i, v in pairs(clientList) do 
      v:close() 
     end 
    end 
    return stopServer 
end 

return S 
+0

当你说在控制台中没有错误,你运行“亚行logcat”看设备的控制台记录或者你只在终端/命令窗口中查看Corona模拟器日志?如果它的后者和你没有使用adb logcat,本教程可能会有所帮助:http://coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/ – 2014-10-26 05:17:26

回答

-1

问题是我添加的权限 “android.permission.INTERNET对”
“android.permission.ACCESS_NETWORK_STATE”
和问题解决

相关问题