Really Confused With TCP Timeout

Alright thank you very much!

To give you a head start.  I run a large networked game using PHP and MySQL for my server.  This is industry standard really.

Now would there be a way to make a “terminal” for the server to do like events, or change data or something without going into MySQL and doing it?

I can just do that with PHP actually right?

You really wouldn’t make a “terminal” though I suppose you could. Instead you can install something like phpMySQL which gives you a web interface to MySQL or an alternate like Adminer (not Ad-Miner, which will sometimes trigger malware scanners, but Admin-er, it’s legit).  

Or do what I did for my Trivia game and build custom PHP-MySQL-HTML5 forms to do admin tasks from a web browser. I had an account management screen and a question management screen. By having custom forms, it makes hiring help easier if they don’t need to know how to query a database but can search by emails and type and submit.

Now to all of this discussion about using sockets vs. web requests. It comes down to core speed.  HTTP/HTTPS requests are simply slow. Corona has to open a previously unopened port, which requires an DNS lookup and then ask the webserver to request a page. The webserver, usually Apache has to parse the request, split out the GET or POST key-value pair parameters, start up a PHP session, which has to interpret your script, which has to open your SQL database and run the query, encode the data, output it and the webserver has to send it back.  Sounds awful, but we are talking half a second to a couple of seconds to make a query assuming the server is playing nicely. Your connection is closed and the webserver can go on to talking to someone else.

This is perfectly fine is for turn based games or games like my trivia game. For some chat/messaging systems this is probably fast enough too.

Sockets are the basis that everything works on. HTTP web servers, FTP servers, Mail servers, etc. all are making some form of socket connection to do the work.  The reason we discourage it, is an HTTP request can be done in one line of code and a function to handle the results. All you need is a URL. That’s pretty simple. With sockets, you have to open the socket and bind to it, once you have the connection established, you have to understand the protocol the server is talking and format your packets accordingly. Your server has to know how to unpack said packets arbitrarily operate on them and return some result. It’s considerably more work than making a network request. So why do it… Because it’s fast. If you have a good connection to the server, you can be exchanging messages in times measured in milliseconds instead of thousands of milliseconds. Your server needs to take that data and get it to your other players with the same speed. You don’t disconnect from the server until you’re done so each message doesn’t suffer the startup-connection overhead. HTTP cannot do this. Now of course somewhere along the way someone created Web Sockets which in a nutshell is a long lasting connection to the web server. I’ve never used them but a Corona user David Mccuskey created something called DMC Web Sockets. http://docs.davidmccuskey.com/getting+started±+dmc-websockets

GameSparks, one of our third-party partners who does games as a backend service actually uses his library for their plugin.

This can get you in between having to write low-level socket code and HTTP requests. You might want to look into it if you find HTTP requests are too slow for your needs.

Now to the question asked waaaaay back up at the top.

Unless  your client and server are running on the same device, both of them cannot connect to “localhost”. “localhost” means “connect to myself” or “listen to myself”. It’s perfectly fine for servers to listen using “localhost”, but your client usually needs a domain name or IP address to connect to*.

* not recommended to connect to an IP address as they change, make sure to setup a DNS record and give your server name that can still exist if the IP address behind it changes.

Rob

They are both running on the same device and getting the error.

Also ran the app on my phone and is still doing the same thing.

So your intent is to have your server run on a mobile device or run as a foreground app on a desktop? What are your long term server plans?

Rob

My plan is to have the Lua Server file run on a server (VPS right now) and have the phone connect to the server and send messages and and data.

Depending on who your hosting provider is you will probably find you are not able to run lua or anything non-standard on it.  So I really would stick to network.request() and use MySQL/PHP.  

FYI, I have a MySQL/PHP solution processing almost 30GB per hour with no problems or noticeable lag on the client.

But I am doing this locally on my computer for testing and it is not working.

I can’t see how you’re calling your module. I’m also not sure why you’re adding functions to network.* when you have your own networking table. I also can’t see where you ever send the message if the initial connection isn’t made. 

Perhaps share a little more code.

Rob

I’m using the Composer library so I have a network module.

This is the code where I called the module. And all I’m doing right now is trying to get the server to read the message:

local scene = {} local composer = require("composer") local widget = require("widget") local networking = require("src.modules.networking") local scene = composer.newScene() local screenWidth = display.viewableContentWidth local screenHeight = display.viewableContentHeight function login() networking:send("this is a login message, so dab on the left, and dab on the right") end function scene:create() local sceneGroup = self.view usernameBoxBackground = display.newRect(screenWidth/2, screenHeight/2 \* 1.5 - 49, 300, 39) usernameBox = native.newTextField(screenWidth/2, screenHeight/2 \* 1.5 - 49, 300, 39) passwordBoxBackground = display.newRect(screenWidth/2, screenHeight/2 \* 1.5, 300, 39) passwordBox = native.newTextField(screenWidth/2, screenHeight/2 \* 1.5, 300, 39) loginButton = widget.newButton({ width = 120, height = 48, label = "login", shape = "rect", fillColor = {default={1, 1, 1, 1}, over={1, 1, 1, 1}}, onEvent = login }) usernameBox.hasBackground = false passwordBox.hasBackground = false usernameBox.placeholder = "username" passwordBox.placeholder = "password" passwordBox.isSecure = true loginButton.x = screenWidth/2 loginButton.y = screenHeight/2 \* 1.5 + 54 sceneGroup:insert(usernameBoxBackground) sceneGroup:insert(passwordBoxBackground) sceneGroup:insert(loginButton) sceneGroup:insert(usernameBox) sceneGroup:insert(passwordBox) end function scene:show(event) if event.phase == "did" then composer.setVariable("lastScene", composer.getVariable("currentScene")) composer.setVariable("currentScene", "src.panels.login-signup.login") end end function scene:hide() local sceneGroup = self.view end scene:addEventListener("create", scene) scene:addEventListener("show", scene) scene:addEventListener("hide", scene) return scene

Also, what is your guy’s thoughts on using Firebase for this kind of stuff?

I’ve always worked under the principle of don’t re-invent the wheel.  If you have custom server needs like instant message passing or having the server enforce game rules then of course you need to do your own thing.  But if you need basic things like account management, saving game states so all clients can get the current game state, etc. there isn’t a reason to not use something like Firebase. Scott Harrison has built out quite a rich state of plugins for this.  We also have PlayFab and GameSparks plugins using their BaaS (Backend as a Service) platforms that are dedicated to helping build multi-player games.  Even if you need high-speed communications, there is Photon cloud which does the heavy server lifting for you.

I spent a good 10 years of my life building server infrastructure and dedicated servers for games. It’s a lot of work. I did a lot of socket layer programming to make this work. With the exception of the unique game servers, my life would have been a whole lot better had we had REST API’s to manage the customers and their access to the system as a whole. 

Rob

Now do you know why the TCP stuff is still timing out?

No. I would probably need to see your whole project, but I’m not going to have time to look at it. Maybe one of our community developers could look at it for you.

Rob

Firebase is build for apps first and games second. Not saying that you cannot use firebase for games. If you don’t want build own server firebase makes perfect sense. Firebase offers a free service. Also all firebase services are now implemented. I sounds like you are making an app and not a game so it is hard to photon, gamespark, or playfab. To @sgs point your own server is great if you have the knowledge and resources to do this but for small simple apps it is hard not to recommend firebase.

Now I was looking at Firebase and wondered if somebody could get a hacked client and screw up other data in the database or is there some way where the user can only edit a certain set of data, and all other data is restricted to them.

Firebases default options require user to be signed to Firebase Auth. Firebase is pretty secure, I mean it is maintained by google.

(nb: did not read entire thread, only commenting re first post)

in both the client and server code you explicitly set the timeout to zero seconds.

that’s brutal - nothing on the internet is that fast, so of course it times out