first of all i tried the normal example that Corona has,
(to connect with TCP server)
\_M = {} local connectToServer, createClientLoop local socket = require( "socket" ) function connectToServer( ip, port ) local sock, err = socket.connect( ip, port ) if sock == nil then print ("couldn't connect to server") return false end sock:settimeout( 0 ) sock:setoption( "tcp-nodelay", true ) --disable Nagle's algorithm --sock:send( "we are connected\n" ) return sock end function createClientLoop( sock, ip, port ) local buffer = {} local clientPulse local function cPulse() local allData = {} local data, err repeat data, err = sock:receive() print ("err: ".. err) if data then allData[#allData+1] = data end if ( err == "closed" and clientPulse ) then --try again if connection closed connectToServer( ip, port ) data, err = sock:receive() if data then allData[#allData+1] = data end end until not data if ( #allData > 0 ) then for i, thisData in ipairs( allData ) do print( "thisData: ", thisData ) --react to incoming data end end for i, msg in pairs( buffer ) do local data, err = sock:send(msg) if ( err == "closed" and clientPulse ) then --try to reconnect and resend connectToServer( ip, port ) data, err = sock:send( msg ) end end end --pulse 10 times per second clientPulse = timer.performWithDelay( 100, cPulse, 0 ) local function stopClient() timer.cancel( clientPulse ) --cancel timer clientPulse = nil sock:close() end return stopClient end function \_M.connectToTCP (\_ip, \_port) local localSocket = connectToServer( \_ip, \_port ) if (localSocket) then createClientLoop( localSocket, \_ip, \_port ) else print ("couldn't connect sucssfuly to server") end end return \_M;
that fails to compily becouse it has a problem with the line
if ( #allData > 0 ) then
so if i remove the statement …
it simply does
error: timeout…
pls ? can you help me why is my server not working ?