I have made excellent progress on iPod Touch client that will be connected to a local classroom network (no Internet). We two servers:
- main TCP server: passes messages back and forth among clients and a shared display (on a computer). It also sends one way messages to a robot server.
- robot UDP server: receives messages only from the main TCP server and sends data directly to the clients and shared display over a UDP connection (lossy is ok).
These two servers are already working very well on a laptop (or desktop) computer.
I am struggling to make the Corona SDK iPod Touch client. Here’s what I need to do:
- create a UDP listener that processes the incoming data stream from the robot server and updates the graphical display.
- create a two-way TCP connection that sends and receives messages from the main server. These received messages can be either responses to a message sent, or initiated by the server.
At the moment the UDP and TCP connections are on different ports. I find a great deal on the Corona site about ads and http networking. Are there any good examples of TCP and UDP networking I can follow? I have read through the Lua Socket documentation.
I have been able to connect with both the UDP and TCP connections, send a message and receive a reply like:
local socket = require "socket" local tcp = socket.tcp() tcp:connect(address, port) local function handleButton (event) if event.phase == "began" then … else event.phase == "ended" then local response = tcp:send("login USERNAME") print(response) response = tcp:receive() print(response) end end
If I try to click the button again, it hangs. The server is sending back a response each time. I don’t have a good idea how to receive messages pushed by the server when the client hasn’t sent anything.
I realize these are probably questions with simple answers. If anyone could direct me to relevant examples I would much appreciate it.
–Scot