Noobhub - Free Opensource Multiplayer And Network Messaging For Coronasdk

Tyler, have you updated client’s lib (noobhub.lua file) ?

In latest version I implemented auto-reconnect if connection gets broken (timeout or anything else), I believe this should fix your issue.

@drazen007bond

In my game I implemented simple command recognition engine, so game can receive some command to change coordinates of something, and do it. For that, game subscribes to a dedicated channel, like, “debug-channel”.

I set-up my php script to connect to the same channel “debug-channel”, and type commands. 

@overtorment Yes the noobhub.lua and node.js files im using are both the newest versions. I’m getting this error that socket is not writable in 2 different VPS’s that im using. Any idea what could be causing this? Note: This error only shows up after using the socket for a bit, it usually doesn’t happen right away after using a new channel id. For example, normally my app gives a user a new room ID when hosting a new room, and room id’s are between 10000000 and 99999999. However, for testing purposes I’m manually setting the room code so that all my devices are on the same channel while developing. Once I get this error, that room id, for example another room id(channel) that as of 2 minutes ago doesnt work now is 66748858 This isn’t usable at all. If I went back tomorrow and tried to use it, it would continue to say socket not writeable. This is reset when I stop the node.js and restart it using forever in ubuntu, which I am using to keep the script continually running.

I got that… should use that idea …thnxs!

  1. Check noobhub.lua if it has method   self:reconnect()  If not - this is not latest version

  2. Tell me nodejs version, maybe this is something specific to version

  3. Open server code  (node.js) and make sure that “verbose” is set to true, then, run server without forever.js and redirect output to log file (or check forever.js log files if present). Reproduce the issue and post error messages if any. BTW, I had funny issues when in verbose mode my nodejs server filled whole disk with logs… Maybe that is your case?

@overtorment

  1. Yea noobhub.lua includes the self:reconnect() function. I made sure and also replaced the local version I had with the version on github and it’s still having errors.

  2. Node running on ubuntu, “npm -v node” returns “1.0.106”

  3. Verbose is set to true, and I ended node.js through forever and ran it by node node.js and still got the error a little bit after using it.

I still have all of the forever logs. The error messages that I get are the following:

  • Exception: Error: ETIMEDOUT, Connection timed out

The first time this shows up is right after a client subscription to a channel. The channel is 66748857, I doubt it has anything to do with the channel name being an integer but just wanted to note that. 

After that error message appears, anytime a client attempts to publish to the channel, this error appears:

- Exception: Error: Socket is not writable

That’s not  nodejs version, it’s  npm version

use

$ nodejs -v

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