LuaSockets and a C++ server, only working in simulator? Not device?

So I have a C++ server that accepts sockets and so I figured I would connect Lua (Corona) and C++ together. It works great on the simulator, the C++ server accepts the client socket from it but when I test it out on my phone, my server doesn’t notice anything.

What could be the problem? [import]uid: 49300 topic_id: 30244 reply_id: 330244[/import]

Verify if both the server and the device are in the same network. You may have problems if you are rinning the server on a local machine using cable ethernet and your device is connected in another network (wi-fi or 3G). [import]uid: 65163 topic_id: 30244 reply_id: 121184[/import]

Yeah they are both on same wifi network. The server is connected through wifi also. Is LuaSocket fully supported on Corona? I think I may have found the problem also in build.settings, Will report back here if it works. [import]uid: 49300 topic_id: 30244 reply_id: 121208[/import]

Here is my client.lua
[lua] myClient = socket.connect(“localhost”, 666);
myClient:settimeout(0);
if (myClient ~= nil) then
print(“CLIENT: Successfully connected to Server!”);
else if (myClient == nil) then
print(“CLIENT: Could not connect to Server!”);
end
end[/lua]

So it still isn’t working on device, even added “android.permissions.INTERNET” to the build.settings but still won’t work.

Any ideas? [import]uid: 49300 topic_id: 30244 reply_id: 121210[/import]

Great! I just got it working after picking at it for 4 hours. [import]uid: 49300 topic_id: 30244 reply_id: 121225[/import]

Glad you got it working… Perhaps you should post your cure here for others who run into this problem.

I’m guessing it has to do with:

myClient = socket.connect(“localhost”, 666);

I bet your server was running on the same computer as your simulator and your server was listening on port 666. When you moved it to you device, its trying to open a connection to your device (“localhost”) and not your computer with the server.

For those who are new to this. “localhost” is the computer the app runs on. So if its running on an iPad, localhost is the iPad not some other server. If its running on your Mac or PC, its the Mac or PC.
[import]uid: 19626 topic_id: 30244 reply_id: 121239[/import]

You are correct! I connected to “127.0.0.1:666” and the server shows a connection accepted. I went on the android browser and typed the same address and it wouldn’t connect! So I tried my local ip address which was “192.168.1.69:666”, it worked on the android browser but not Corona. So I rented out a.VPS and connected to that ip and it worked. I was so happy to see the word “connected”
[import]uid: 49300 topic_id: 30244 reply_id: 121262[/import]

Verify if both the server and the device are in the same network. You may have problems if you are rinning the server on a local machine using cable ethernet and your device is connected in another network (wi-fi or 3G). [import]uid: 65163 topic_id: 30244 reply_id: 121184[/import]

Yeah they are both on same wifi network. The server is connected through wifi also. Is LuaSocket fully supported on Corona? I think I may have found the problem also in build.settings, Will report back here if it works. [import]uid: 49300 topic_id: 30244 reply_id: 121208[/import]

Here is my client.lua
[lua] myClient = socket.connect(“localhost”, 666);
myClient:settimeout(0);
if (myClient ~= nil) then
print(“CLIENT: Successfully connected to Server!”);
else if (myClient == nil) then
print(“CLIENT: Could not connect to Server!”);
end
end[/lua]

So it still isn’t working on device, even added “android.permissions.INTERNET” to the build.settings but still won’t work.

Any ideas? [import]uid: 49300 topic_id: 30244 reply_id: 121210[/import]

Great! I just got it working after picking at it for 4 hours. [import]uid: 49300 topic_id: 30244 reply_id: 121225[/import]

Glad you got it working… Perhaps you should post your cure here for others who run into this problem.

I’m guessing it has to do with:

myClient = socket.connect(“localhost”, 666);

I bet your server was running on the same computer as your simulator and your server was listening on port 666. When you moved it to you device, its trying to open a connection to your device (“localhost”) and not your computer with the server.

For those who are new to this. “localhost” is the computer the app runs on. So if its running on an iPad, localhost is the iPad not some other server. If its running on your Mac or PC, its the Mac or PC.
[import]uid: 19626 topic_id: 30244 reply_id: 121239[/import]

You are correct! I connected to “127.0.0.1:666” and the server shows a connection accepted. I went on the android browser and typed the same address and it wouldn’t connect! So I tried my local ip address which was “192.168.1.69:666”, it worked on the android browser but not Corona. So I rented out a.VPS and connected to that ip and it worked. I was so happy to see the word “connected”
[import]uid: 49300 topic_id: 30244 reply_id: 121262[/import]