Hi,
in my server class I have these functions:
local socket = require("socket") function M.setupSocket() print("serverCommuncation.setupSocket()") master = socket.tcp() return master end
function M.connectToServer() master:settimeout(1) --serverResponse = master:connect( "127.0.0.1", 8000) serverResponse = master:connect( "192.168.0.3", 8000) if serverResponse == 1 then print("Connected to server") else print("Could not connect to server") end return serverResponse end
And the main.lua file looks like this:
local server = require( "communication.serverCommunication") local storyboard = require( "storyboard" ) print("MyIP: " .. tostring( server.returnMyIP() ) ) server.setupSocket() local count = 0 while server.returnMaster() == nil and count \< 100 do print("serverCommunication.returnMaster(): nil") count = count + 1 end if server.returnMaster() ~= nil then local serverResponse = server.connectToServer() if serverResponse == 1 then -- Proceed else -- Error end else print("Not connected to master") end
And when running this program in the simulator it works and I get a response from the server however I’m having problem with the program on the device. First I though it was because of the local IP or something like that but the problem is that master = socket.tcp() is never assigned.
I/Corona (16146): serverCommunication.returnMaster(): nil
Can anybody help me with this as I’m not really sure what the problem is. Why is “master” never assigned by socket.tcp() ?
Best regards,
Tomas