Noobhub - Free Opensource Multiplayer And Network Messaging For Coronasdk

I’ve checked the code, looks like in server code I need to implement another event handler,

socket.on('timeout'

and it should do same stuff as  socket.on(‘close’,

you can copypaste the code yourself, meanwhile Ill push it to the repo.

Client code should handle it and reconnect automatically.

Hi

I´m using a noob hub for a small game i´m developing. I have checked that noob hub and it stores the socket information in an internal array. Which means that it is not possible not make the service grow horizontally since two machines running noob hub wont have the same socket information. 

Is it possible to store the socket  information in any sort of database and then make several nodes read that information?

Hi Overtorment / all,

Did you guys test how noobhub (latest version) in Corona behaves on a very bad internet connection (either from the client or temporary from the server)?

My app (in development) could hang then and give sometimes an error “attempt to index global ‘hub’ (a nil value)” when going to a storyboard scene which makes a new noobhub connection.  Also noobhub.lua gives sometimes “attempt to index field ‘sock’ (a nil value)”.

I hope you’re willing to test this in the simulator :

Download the network link conditioner

http://mattgemmell.com/2011/07/25/network-link-conditioner-in-lion/

Simulate for example Edge lossy network and make a new profile with extra packets drops and seconds delay. 

Just try to stress the internet connection so bad until noobhub needs some time to connect when starting your app or entering a scene.

I dont care if players cant make a connection, but the app just freezes and will hang cuz of the errors, with no choice to shut it down hard.

Besides some handling of these errors, Noobhub shouldnt block runtime while trying to connect. 

For example in my main menu I check via noobhub if there is new version of the app. When there is a bad connection the app gets unresponsive until it gets an answer or connection fails.

This might also be some help: http://stackoverflow.com/questions/14203163/how-to-run-blocking-operation-in-corona-sdk-lua

thx a lot

You can read out the socket.connection_id and socket.channel, so I would think that is possible.

So if I understand correctly, I could store socket.connection_id and socket.channel in a database and then instanciate the socket using those values

I am not sure what your question is. However if you would like to put 2 players together just move them to the same channel. So you can have lots of pairs or groups of players in different channels. For random matchmaking I just check if the waiting channel has more than 1 player and then send a message to Corona with a new unique channel name, which they can move to. For a lobby you could make a lobby room channels and when everybody clicks ready in their app, move them to a unique game channel. No need to use the connection_id or a database for that. 

What I mean is that I have noob hub in one server, but if I want to have 2 or more noob hub servers running and load balance between them is not possible since the channels and the sockets are not shared between the different servers. I was wondering if there is anyway to make noob hub horizontally scalable .

Scaling is actually easy. You can do it like with usuall sharding in databases. Once clients negotiated about a new match in lobby, they should decide uniq channel name. Based on uniq channel name, client should create new subscription to one of the predefined servers. For example, game interactio is going to be in channel 12345, and since its an odd number, create a new noobhub object on server 2. If it were even number - create it on server1. Scaling can go almost infinite - choose your own sharding algoritm. You can even move this algoritm to your backend, and make a calls like “give me the address of server I should use, if my channel name is …” But I actuallly doubt youll need this scaling instantly, as nodejs can hold up to 1 million connections on properly tuned and powerfull enough server. But you can use this as a way to ensure uptime, if one of the nodejs servers goes down suddenly.

Regarding the network issues - Ill be looking into this next week. Thats a bit strange, because I was coding client with non-blocking operations. If youll manage to fix stuff before I do - dont be shy to contribute to github repo…

Ok :) . I made a pull request to fix the “attempt to index field ‘sock’ (a nil value)” error.

The ui blocking is still a problem on very bad connections.

To add on to what @overtorment said, I came up with a very easy way to scale your servers. For all of my games/services, I always create an update.lua file that runs right after main.lua. In that file, depending on what the app is, I check the app has internet, check the version code of the current version the user is using matches with the version code stored on my server, and if its a game with stored settings, I download the newest settings from my server and save them into json files using the loadsave library. In one of my games, I have multiple game modes. One very easy way for me to scale the game would be to store a php array on my server saying something like:

$settings = array(); $settings['modes'] = array( //SET THE NOOBHUB IP'S FOR EVERY MODE 'mode1' =\> '000.000.000.000', 'mode2' =\> '000.000.000.000', 'mode3' =\> '000.000.000.000', ); echo json\_encode($settings);

000.000.000.000 would be replaced with the ip of each different server that you want to use for each different mode. Then in my update.lua file, I would network.request that php file on my server, then I would say:

local modeInfo = {}

local response = json.decode(event.response)

for key,value in pairs(response) do

       if key == ‘modes’ then

              for key,value in pairs(value) do

                     modeInfo[key] = value

              end

       end

end

loadsave.saveTable(modeInfo, “modeInfo.json”)

Now you can go into the different lua files for each mode, and if its mode 1 for example, say:

local modeInfo = loadsave.loadTable(“modeInfo.json”)

–this will be the variable we input into the new hub connection as the ip to use

local ipUse = modeInfo[‘mode1’]

and Bam. you now control what ip address every mode uses just by changing a simple array on your website. Sorry if that was a bit lengthy, but hope it helps!

Tyler

Thanks for your help. Now I have more possibilities. But what I had in mind is to have my silly load balancer to control the load, and be able to automatically spawn a new noob hub instance in case of lack of performance or failure without compromising the service.

With both of your solutions I have to increase the complexity in the game side. I was looking for a solution where noob hub servers would be more independent.  I will probably implement one of the two solutions since I don´t find any way to do it as I imagine.

Also since you said that it can take 1 million requests I feel more comfortable with it :slight_smile:

To prevent noobhub from blocking UI (buttons and actions) when there is bad or very slow connection I use this check from aukStudios before making a hub connection :

http://forums.coronalabs.com/topic/33356-check-for-internet-connection/

With settimeout(1) . Not sure if this is the best way to handle this, but it seems to work ok for now.

Hello there,

Noobhub just gave birth to my new idea and so many others! Congrats!

Now, I am having problem on deploying node.js on server.

When I call node node.js on my server, NoobHub initialize and console give me this message: Noobhub on 0.0.0.0:1337

I opened up port 1337 from my router but with no hope. I tried the sample app on corona with no success…

Please enlight me,

Thanks again,

Yiannis Demetriades

I think I understood where the problem is in Noobhub. During the initial connection, I didn’t set up zero timeout… Ooops, here are UI hangs if theres no internet at all :slight_smile: I just never tested this case… :slight_smile:

Didn’t get why you opened port on your router… Server with nodejs is supposed to have public accessible IP with no magic with routing. And client (corona sdk) is able to connect to it through any router from any subnet (with exception of networks with explicit security).

My test server IP is hardcoded in demo code, you can use it meanwhile you set up your own server.

@Overtorment

It works with your server nut I have to find the way so will work on my own server. I have Ubuntu Server. I dont know if this helps. Maybe a port opening, something in iptables… Something… Just give me your lights

Thanks again

When noobhub starts what is the console output?

My output is Noobhub on 0.0.0.0:1337
Is that right?

@yiannis yes, when you run the script that is the first thing that shows up in the log. that means you have successfully started the script

Hey @overtorment, the node.js script is still pretty extensively having the “Exception: Error: Socket is not writable” issue. My app released this weekend, and in my logs for node.js running through forever, there are a LOT of instances of this error. Do you have an email where I can send you my log if that would help? I’m hoping this is something simple that can be fixed soon so that people don’t start giving low ratings about the online part of the app.

Send log to overtorment at gmail com Ill take a look asap. Include node js version $ nodejs -v Is noobhub server library latest?