What am i doing wrong with connections? [Updated and works again]


#1

Hi guys.

I am making a multiuser prototype and i try to stabilize the connection.

The application runs here: http://multiuser-prototype.meteor.com
(Press 1 to show/hide console)
(Press Q to freeze/unfreeze camera)

It takes too long to user to connected and if done, he dont see the other connected user.

I do not have these problems in my local app.

Any help ???

Thank you.


#2

I am making a multiuser prototype and i try to stabilize the connection.

It works all right. Just need too long time to stabilize connection.

http://multiuser-prototype.meteor.com/viewports-2x.html

How will I get a connection faster?

Please if you try it sent a feedback.


#3

Some help here guys.

I made this multiuser prototype http://multiuser-prototype.meteor.com/viewports-2x.html

and it works good in web but… (always there is a but)

I have a small problem with connection.

If I have the window of the page and it render during connecting It take too long to estabilish the connection.
If I hide the browser in the task toolbar then it is connecting fast. I do not know the reason.

Do anyone can help to solve this problem ?

I try to found a way to not render the page before the connect complete.
Do any of you out there can help me?

Pleaseeeee ???


#4

You should probably share some code.

It’s difficult to understand where the blockage is


#5

Here is the code for the Meteor part. Any help welcome.

   // JavaScript Document
$(function()
{

//  Meteor connections.

    connection = Meteor.connection;
    myconnection_id = connection._lastSessionId;
    someCollection = new Mongo.Collection( "anyname" );
    subscribe = Meteor.subscribe( "setname" );
    myrecord_id = sceneCollection.insert({  connectid: connection._lastSessionId, 
                                            nickname: myNickname,
                                            registed: false,
                                            //  ..........  //
                                            isPlayer: true 
                                         });

    animate();
    
    
    function animate() 
    {
        requestAnimationFrame( animate );
        renderer.render();
        Meteor.reconnect();
        var thefetch = someCollection.find({selector: selector}).fetch();
        var i;
        for (i in thefetch)
        {
            if ( thefetch[i].isPlayer ) 
            {
                // some mambo jumbo here  //
                
                // .....................  //
                
                // more mambo jumbo here  //
             }   
             
            if ( thefetch[i]._id == myrecord_id )
            {
                //  Some updates here   //
                
                // ...................  //

                //  more updates here   //
            }
        }

        Meteor.reconnect();
    }
    
});

#6

http://docs.meteor.com/#/full/meteor_reconnect

Meteor.reconnect();

This method does nothing if the client is already connected.

I could be missing the context here, but you seem to be connected when you call the animate() function.


#7

Exactly. I need a way to start animate after the connection have stabilized.


#8

You shouldn’t be using $(function()) its a jquery thing that isn’t suitable for meteor. Meteor.onConnection(callback) should work better maybe. Try this first.

Secondly, meteor has inbuilt connection handling. I’ve never had to call Meteor.reconnect() unless my actual server went down and came back. I’d say remove those.

Its super hard to workout what you are trying to do here it looks like you are trying to make a game. A meteor connection should be instant. My only guess is that your three.js code is blocking too much and interrupting connections. Could you try removing any of the intensive THREE.JS stuff and seeing if the code works.


#9

Hi ahref. Thank you for your respond.
I try to make a connection prototype for a multiuser game with three.js.
Now I have upload in multiuser-prototype.meteor.com this kind of code:

function startupConnection()
{
    connection = Meteor.connection;
    sceneCollection = new Mongo.Collection( "scene" );
    subscribe = Meteor.subscribe( "players" );
    connection.onReconnect = callback_afterReconnect;
    function callback_afterReconnect(){
        //  Add some code here.  //
    }
}

startupConnection( $(function()  {

 // .... ....  //

        init();
        animate();

 
// ..........  //
    

    })
);

Same problem again. When the browser is hidding in task bar it connecting fast. When meteor page it is on screen it is trying to connect.

Meteor.onConnection(callback) is says it is server-side only and I use it in my server.
Can i use it and in client side ?

I will work your advices and let you know.
Thank you.


#10

One more question.

Can i use a script block in the html meteor page? What If i put the three.js code there?
My goal is to start the page rendering after the connection have estabilished.

tip: see the console logs for better understanding.


#11

Some explaine of how this prototype works.

When you open the multiuser-prototype.meteor.com page you connect in the apps server.
You get a guest name a color and an id.

When a new user connecting you should see him in your screen as a cube with a color.

You can open several pages. Every page is an unique user. Every frame is a unique user.

You can have in page several frames. So in one page you can watch 1x, 2x, 3x, 4x or 6x users.
This way you test if it is real-time (or almost real time). Use the 1x, 2x, 3x, 4x and 6x links on left bottom of the page.

Focus the frames with tab key.
Actualy you focus the links that are focus the frame.
Key Q freeze/unfreeze camera postition.
Key 1 show/hide the on screen console. (Works when user is in “connected” mode. In “connecting” mode the console is appearing automatic and you can not hide it.)

tip: for faster connection, hide your browser in task bar. Open the resourse monitor and watch the network activity. When activity get low then you are connected stable. Return to page.


#12

Meteor.onConnection(callback) is server side yes whoops, ignore me in regards to this.

Stop using

$(function(){
});

Its not needed.

As I said previously I think that your rendering logic in THREE.js is blocking meteor from maintaining a connection. This is why when you can’t see the window it connects faster.

You need to optimize the three code so that it does not block meteor.

startupConnection( $(function()  {

 // .... ....  //

        init();
        animate();

 
// ..........  //
    

    })
);

Would be better written as:

startupConnection();
init();
animate();

Without seeing all of your code its impossible to tell why you are having connection troubles. As far as i can tell you are still doing really weird stuff with connection handling that just isn’t needed.

In particular your app polls the server’s info.json multiple times before establishing a connection. Any other app including the examples do not do this.

I can’t figure out why without seeing your application source a github link or something similar would be needed.


#13

what kind of connection you expect? In my prototypes I always expect all connections to be ready in Meteor.startup part.
And with fastrender package user is already logged in.


#14

It works now ! wow !


#15

Updated and works again. http://multiuser-prototype.meteor.com

Meteor is so simply that I always get confused. lol.