codingdir logo sitemap sitemap |
Home
PHP
C#
C++
ANDROID
JAVA
JAVASCRIPT
PYTHON

Javascript recursive timeout call


By : , Category : javascript

Change your setTimeout call to

setTimeout(function() { hide(id); } ,1000)

So it will execute after 1s, and not immediately

ReLated :

1) Unless there's a good technical reason for this (you said you read this in many places but didn't give any references) I find the first way much better as it's more clear.

2) The alternative is exactly what you called the "first way".

3) You already solved the problem giving a name to the function so it's not anonymous anymore:

console.log((function a() {
    a();
})());

It's working, but you call slider() again before the fadeOut has completed. Stick the recursive call in the callback:

function slider() {
    $("#img2").fadeOut(3000, function () {
        $("#img2").fadeIn(3000, function() {
            //As Kristof Feys pointed out, you probably want to wait for the 
            //fade in to complete, then call the method.
            slider();
        });
    });
}

A demo as well: http://jsfiddle.net/9k7e3/

That specific server, PHP-Websockets, does not provide support for the wss:// protocol (secure connection, similar to https:// for HTTP traffic).

Change the connection line to:

socket = new WebSocket("ws://myurl.com:9000");

Alternatively, if you need TLS support, PHP-Websockets might not be the best server for you.

I made the decision to not support TLS in PHP-Websockets because I did not know of any robustly tested, battle hardened PHP packages that provide access to the OpenSSL libraries. I have changed my mind as of 5 minutes ago, and will implement TLS using the built in PHP OpenSSL functions, but this will take time to implement and will require several testers. If you don't want to wait, don't wait.

I do not want people to think that their data is secure when I simply can't guarantee it.


Also, not specifically causing a failure but still an issue: In your server-side code, you should change instantiating the server's object to:

$echo = new echoServer("0.0.0.0", "9000");

The reason is that the IP address is setting the server's listen address. The listen address of "0.0.0.0" gets translated to "listen on all IP addresses that this machine can listen to." That means that, besides just your own public IP, it will also listen to 127.0.0.1, and if you have a second network card that has a different IP address assigned to it, you can receive traffic from that as well.

However, because of PHP's weak typing, when socket_bind() attempts to convert the IP address into its binary representation, but finds a string instead, it silently converts it to 0, which is equivalent to the IP address 0.0.0.0.

(I previously thought that socket_bind() was performing a DNS lookup to get the IP address. I was very wrong. Such weak typing on the part of PHP, and especially the assumptions made by developers like me, is the cause of many security holes.)

setTimeout(function(){
    for (var n = functions.length, i = 0; i < n; i++) functions[i]();
}, 2000);
Comments


Message :
Login to Add Your Comments .
How to disable registered OpenCL platforms on Windows?
Is Observable broken in Angular 2 Beta 3?
Cross-thread operation not valid when using Invoke
How to pass an IEnumerable or queryable list of properties from Controller to View
Finding numbers after a certain keyword using Python
Pocketsphinx recognizes random phrases in a silence
Passing non-thread-safe objects through thread-safe containers
React scroll nav
BizTalk WCF-BasicHttp Adapter does not allow Empty string for Service Certificate Props
Why property ''cause" of Exception is repeating forever?
Privacy Policy 2017 © codingdir.com All Rights Reserved .