0

Here I have a code for sum 3 numbers i+j+k but I waht to know how to configure server file to work with setTimeout function... is there some restriction?

so, here is mycode:

index.jade

!!! 5
html
  head
    title Test
  body
    form(name='form1', method='post', action='')
      label(for='1')
      input#1(type='text', name='1')
      label(for='2')
      input#2(type='text', name='2')
      label(for='3')
      input#3(type='text', name='3')
      input(name='submit', type='button', value='submit') 
    span #{result}

app.js

var express = require('express');
        app = express.createServer();

app.configure(function(){
    app.set('views', __dirname + '/views');
    app.set('view engine', 'jade');
    app.set("view options", { layout: false });
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(app.router);
    app.use(express.static(__dirname + '/public'));
});
app.use(express.bodyParser());
    app.get('/', function(req, res){
        var result;
    res.render('index', {result: ''});
});


    app.post('/', function(req, res){
      var i = req.param('1', 0);
      i = parseInt(i);
      var j = req.param('2', 0);
          j = parseInt(j);

      var k = req.param('3', 0);
         k = parseInt(k);

      var r = i+j+k;
      res.render('index', {result:r});

    });
app.listen(3010);

How etc. to block user action (click,doubleclick,rightclick) and show him a div with text "You can do any action" in first 5 seconds and after that user can do action but after 60 seconds again can't do any action... Can I do this with setTimout function or HOW???

sorry for my english

6
  • that easy with javascript on clientside but I need to to with server control user so I need to write that function on serverside file app.js, Can i use setTimeot or??? Commented May 26, 2012 at 14:53
  • click, doubleclick, rightclick and such events only happen in the client side. The server side gets events like a new incoming request. While you can use setTimeout on the server side, that doesn't really change anything. Commented May 26, 2012 at 15:08
  • ok, but is a good solution to show I some div that will cover all screen 5s and then dissaper... so on css i will have a width:100%, height:100% and How I can change visibility on time etc. after 5s... so when 5s over then I change visibility:visible ... or hidden after some time??? Commented May 26, 2012 at 15:12
  • when I cover screen with DIV 100% users can't do anything? :) Commented May 26, 2012 at 15:13
  • Yes they can (with some computer savviness), but you can simply refuse to serve them on the server side if it was less than 60 seconds since last request for example... Commented May 26, 2012 at 15:16

1 Answer 1

1

You cannot do this on the server side. You have to insert a client side javascript that blocks the interaction and unblocks it again after 5 sec.

The code for doing this on the client side would be something like this:

// this code should be executed when the client receives a message from the server.
var overlay = document.getElementById("your-element-id");
overlay.style.visibility = "visible";

window.setTimeout(function () {
    overlay.style.visibility = "hidden";
}, 5000);

You should take the following steps to achieve what you want:
1. The user loads the page.
2. The user receives a message from the server, stating that he is being synchronized
3. Then either after a specified time or after another message from the server you unblock the user
4. Finally you start the game

Sign up to request clarification or add additional context in comments.

11 Comments

ok, but is a good solution to show I some div that will cover all screen 5s and then dissaper... so on css i will have a width:100%, height:100% and How I can change visibility on time etc. after 5s... so when 5s over then I change visibility:visible ... or hidden after some time???
Why exactly do you want to block user interaction for 5 sec? Then I can tell you if this is a good solution.
becouse I'm try to create some relatime app I need the perfect sincronization beetween users so all users to get div100% visibility:visible on same time
I trying to cretate somethin like simple game realtime multplayer and I need to know is better to do this with serverside code like I want, or just with clientside... becouse I need perfect sincronization beetwen users
or maybe i need a open connection with socket.io
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.