Really Confused With TCP Timeout

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

That how they had it in the tutorial. Also I tried different numbers and it still didn’t work.

tutorial???  doesn’t matter…

if you settimeout to zero you’re going to get timeouts, that’s basically inevitable, as you have ASKED it to immediately timeout.

but you also have some weird logic that checks “if (data) …”. else it assumes an error.  (which OF COURSE will be “timeout”)  but it might just be that there was no data left to begin with…  it looks like you’re “polling” tcp to build up the full message in tiny zero-second timeout chunks, and on the last of those chunks you should EXPECT it to return no data and timeout trying.  In fact, I’d expect that EVERY previous call to .receive() was returning a timeout error too - but you’re only reporting the last one (the one without any more data) because of your logic structure.

Not 100% sure but I think 0 in socket means to do whatever, but I gotta check. But like I said, even with a whatever second

timeout, it still returns timeout in the server.

Anyways, if I’m thinking what your thinking, I have the statement to see if there is anything there, because sometimes it is always false.

The rest of the stuff I have no idea what your talking about.

Why use sockets rather than the more mature network library?

Also if you want help then maybe you need to show what is the value of message-  in the scope of function networking:send(message) - and also show any console prints and/or any error messages.

What do you suggest?

did you not read what I posted?

Yeah I saw it, but isn’t socket part of the network library?

The value of message is networking:send(“this is a login message, so dab on the left, and dab on the right”) (don’t judge lol).

This is what I get from the server console: https://gyazo.com/0942af065b210ac900f0eddb0e9df16c

Normally, you would make a network.request() GET or POST to a web server and that would return you your data.  Sockets library is not really for general internet communication.

This is what Corona has to say…

The socket library provides low-level access to the network stack on the host device. It is not intended for general networking usage (the network library is much easier to use). There are a small number of specific tasks that require socket APIs, but these are uncommon and require a level of expertise in network programming that is also uncommon. Any code that uses the socket APIs will need ongoing tweaking as device vendors change rules for network access, for example in regard to IPv6 networks, while code written using the network APIs will generally continue to work because it is directly supported by device vendors.

I very much doubt your app demands synchronous communication so use the network library as that is asynchronous and designed for TCP communication with servers.

Ok so I’m just going to start fresh and say that basically what I want to do is make basically a text messaging app. I recently just decided I wanna have the ability to send images. So is HTTP and/or the network library the best way to do this or is there something else? Also then how would you suggest I made the server?

HTTP runs the world my friend.  There is plenty of information on the corona forums, corona docs, stack overflow on this.  I suggest you do some research and learn how to do it.