I used an example given on the Luasocket website just to try it out, my goal was to make a flash game that'll communicate with the socket.
I run the server and connected to it using telnet at first and it worked, every message I sent appeared on the console so I took it to the next step and connected to it through AS 3 and it did connect but the server won't receive any message even though I constantly write() to it.
Is there anything I'm missing that won't let an actionscript application communicate with the lua socket server?
Code
-- load namespace
local socket = require("socket")
-- create a TCP socket and bind it to the local host, at any port
local server = assert(socket.bind("*", 0))
-- find out which port the OS chose for us
local ip, port = server:getsockname()
-- print a message informing what's up
print("Please telnet to localhost on port " .. port)
print("After connecting, you have 10s to enter a line to be echoed")
-- loop forever waiting for clients
while 1 do
-- wait for a connection from any client
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
Actionscript:
var sock:Socket = new Socket();
sock.connect("127.0.0.1",3335);
stage.addEventListener(Event.ENTER_FRAME,test);
public function test(e:Event):void{
sock.writeUTF("Hello world");
}