Search code examples
androidlualuasocket

LuaSocket server don't accept clients


Im making a lua script running at my pc, and need to connect from my android. So in the lua script I just put this:

local socket = require 'socket'
local server = socket.tcp()
print("createdserver")
server:bind('*',7070)
print("binded")
while 1 do
  server:listen(32)

  local client = server:accept()    

  -- make sure we don't block waiting for this client's line
  client:settimeout(10)
 -- receive the line
  local line, err = client:receive()
  -- if there was no error, send it back to the client
  if not err then client:send(line .. "\n") end
  -- done with client, close the object
  client:close()
end

And at android I got a really simple socket connection:

public Connection(String ip, int _port) {
    //inMessage = new NetworkMessage();
    buffer = new byte[16394];
    try {
        serverAddres = InetAddress.getByName(ip);
        socket = new Socket(serverAddres, _port);
        socketOut = socket.getOutputStream();
    } catch (IOException e) {
        Log.e("Connect", e.getMessage());
    }
}

At android it just stays at "new Socket" and dont connect.


Solution

  • My notebook was changing its IP address so I couldnt reach it from the android, already solved!