socketio / socket.io-client Goto Github PK
View Code? Open in Web Editor NEWRealtime application framework (client)
Home Page: https://socket.io
License: MIT License
Realtime application framework (client)
Home Page: https://socket.io
License: MIT License
hi, I am using socket.io on the client and node-socket.io server. transports: [websocket]
everything works fine, but when the socket disconnects on the client it's not possible to connect again.
socket.connect() returns an socket object, but no connection is made nor callbacks fired.
the socket.connected = true, after disconnect()
thx, dz
Do you plan something like
socket.on('error', function(){} );
when server is unreachable (when it doesn't exist or network is disconnected).
Transports should expose if they're cross-domain capable, and when io.Socket
is initialized with a host different from document.domain
, the domain check should be incorporated.
We should fire the disconnect event and cancel all the (ongoing) requests to the server through:
These should cover two scenarios:
Hey,
First off, I'm really excited about using this framework! I have it working perfectly on Chrome and there's so many possibilities.
But I'm kind of stumped here. How do I get it to work with Firefox and Safari? They are both using the Socket.prototype
functionality (logging the javascript), how should I go about debugging this? What are some reasons why it might not be working? Here is the client-side code I'm basically using:
$(document).ready(function() {
// where ./javascripts/socket.io/ is the root
// directory of the socket-io project I downloaded from github
io.setPath('./javascripts/socket.io/');
socket = new io.Socket(null, {port: 8080});
socket.connect();
socket.addEvent('message', function(data) {
alert(data);
}
socket.send("Hello")
})
And then I copied the chat example from the socket.io-node project for the node.js server. Any thoughts how to get this working?
Fails with:
Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)" location: "http://localhost:8000/mockingbird/staticjs/socket.io/socket.io.js Line: 335"
Hi, i encountered a problem when trying to use the WebSocket transport. I noticed that the WebSocket connect seems to work fine to connect to my web app (built using Rack), but Socket.IO don't know if the connect call was successful or not.
I noticed that the onopen() event of the WebSocket object, is not connected to the _onConnect() callback in the transport object. I added that assignment, and is now working fine.
Perhaps this is a fix to this problem. Can't seem to find any other issue reported here on GitHub, encountering the same problem with the WebSocket transport.
Here's the commit object:
http://github.com/markjeee/Socket.IO/commit/b408584e854de903cd3dfa68f1e26501901fbdd4
If you think this is not a problem, please just disregard.
Many thanks!
Mark
I've had issues with IE6 (without Flash)
/lib/socket.io/transports/htmlfile.js:24
self.response.flush();
TypeError: Object .a ServerResponse. has no method 'flush'
response.flush() is used 3x in htmlfile.js.
I used a
if ('flush' in this.response) this.response.flush();
To fix it but have no clue if that's the best way.
This happens when sending a message in FF 3.6 using xhr/multipart (though the message still gets received and processed). I'll try to submit a patch for it if you don't get to it before me.
i put this in a new issue.
on IE 6.0 happens no fallback if flash is not installed - can this be fixed?
socket.connect() returns true and there is nothing "wrong" with the connect - but nothing happens - there is not even a connection going in any way to the server...
thanks!
socket.io.js
FABridge.prototype.root = function(){
return this.deserialize(this.target.getRoot()) <-- Boom
getRoot
is undefined
May just be an issue with the beta tho.
For me, specifying this as transports seems to work in all browsers I tried:
['websocket', 'flashsocket', 'xhr-polling']
htmlfile didn't seem to work for me in IE8... xhr-multipart I'm not sure about, maybe test some more.
IE8 continues to connect multiple times with XHR-polling, goes in loop and therefore hangs the browser.
Dev. console shows that in onreadystatechange event,
the self._xhr.status has value "Unspecified error."
On the server side, the log is full of connects and disconnects.
This is how I'm loading socket.io
<script src="js/Socket.IO/socket.io.js" type="text/javascript" language="javascript" charset="utf-8" />
<script type="text/javascript" language="javascript" charset="utf-8">
io.setPath('js/Socket.IO/');
</script>
And here is the error I'm getting on firefox, as I assume normal websockets don't work yet and it's using the flash fallback:
[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf
I have tried manually setting the websocket location using
window.WEB_SOCKET_SWF_LOCATION = 'js/Socket.IO/lib/vendor/web-socket-js/';
To no avail. Any ideas?
Shouldn't it be XHR as there is no support for Websockets
I'm using the example chat app, with an added line:
setInterval(function(){ console.log(socket.connected); }, 100);
The behavior I'm seeing is as follows:
Any hints as to what's going on here?
Attempting to run Firefox 3 without flash, using either of these two sockets, causes an error (Specifically, this._xhr.send(); in each of them is considered to be missing an argument)
I have noted that in 3.6, without flash, these plugins work.
The for...in statement iterates over user-defined properties in addition to the array elements. This breaks code when Array have some user-defined properties (e.g. mootools library is in use).
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Statements/for...in#Description
Per Matt Stevens feedback
hi, flashsocket transport doesnt work on my firefox.
When I load WebSocketMain.swf (I tried it also with WebSocketMainInsecure.swf) I get the following error from flash:
Verify Error: Error #1033: Cpool entry 42 is wrong type
then after clicking at continue:
Reference Error: Error #1065: Variable WebSocketMain is not defined
Firebug doesn't return any errors.
thanks! best, danielzzz
For two reasons:
It will
There seems to be a problem with the way queued messages are sent (i.e. messages that are added to a queue because they are "sent" before the connection is established), at least over the WebSocket protocol.
I have some client-side code that looks like:
websocket = new io.Socket('localhost');
websocket.connect();
websocket.send(JSON.stringify({"first": 1}));
websocket.send(JSON.stringify({"first": 1}));
websocket.send(JSON.stringify({"first": 1}));
setTimeout(function() {
websocket.send(JSON.stringify({"second": 2}));
websocket.send(JSON.stringify({"second": 2}));
websocket.send(JSON.stringify({"second": 2}));
}, 2000);
If I dump the raw messages, as they appear on the server with some code like
client.on('message', function(message){
sys.puts(sys.inspect(message));
});
then I get the output
'["{\\"first\\":1}","{\\"first\\":1}","{\\"first\\":1}"]'
'{"second":2}'
'{"second":2}'
'{"second":2}'
I made a patch to fix this, which results in the second style always being received by the server, for both queued and non-queued messages:
diff --git a/lib/socket.js b/lib/socket.js
index 3066872..3687eaf 100644
--- a/lib/socket.js
+++ b/lib/socket.js
@@ -95,7 +95,9 @@
Socket.prototype._doQueue = function(){
if (!('_queueStack' in this) || !this._queueStack.length) return this;
- this.transport.send(JSON.stringify([].concat(this._queueStack)));
+ for (var i = 0; i < this._queueStack.length; i++) {
+ this.transport.send(this._queueStack[i]);
+ }
this._queueStack = [];
return this;
};
(I think these will probably also be in the pull queue.)
This is more of a feature request than an issue, but I don't run my node apps as root, and 843 is one of the privileged ports. I manually patch socket.io to change the port. (I have a iptables rule to NAT 843 to the higher port).
It would be cool if this were an option so I don't have to apply a patch to ever release of socket.io.
Thanks.
I consistently get the error below when I run the server (test/server.js):
Error: Must have start <= end
at Stream.ondata (http:526:27)
at IOWatcher.callback (net:307:31)
at node.js:748:9
This kills the server too... any idea why?
I've tested this in Firefox 3.6 using Charles Proxy set to 250ms and 400ms. I have an app where I send messages to the server and wait for a response. In high latency environments, I've seen that some messages never make it to the server when I do many actions very quickly (I only ever send one message at a time - so it's not a problem of sending many messages concurrently as each subsequent message waits for the ack from the previous message). I've pasted a sample run of the app from firebug - the random string of characters are unique identifiers on the messages: http://gist.github.com/592812
On the server side, I'm printing the message id on client.on('message') and all that is output is:
qjDG0g
Will try to dig more into this soon, but just wanted to post this here in case anyone had any ideas.
When the xhr-polling transport is used (tested from an iPhone and an iPad), sending data from the client to the server at the wrong time causes a spurious disconnection.
To reproduce, just add such a snippet to the chat.html example:
socket.on('connect', function() {
send();
});
On the data has been sent, the connection breaks after a few seconds:
27 Aug 00:25:32 - Initializing client with transport "xhr-polling"
27 Aug 00:25:32 - Client 7475254631135613 connected
27 Aug 00:25:43 - Client 7475254631135613 disconnected
27 Aug 00:25:53 - Couldnt find client with session id "7475254631135613"
27 Aug 00:25:53 - Couldnt find client with session id "7475254631135613"
27 Aug 00:25:53 - Couldnt find client with session id "7475254631135613"
console.log(socket.connected) => false
The page only shows: Connecting...
Firefox 3.6.8 works ok with the same server.
I tried to use your transportOptions, but it didn't work because of an error here:
@@ -46,7 +46,7 @@ io.util = {};
return clone;
} else if (typeof item == 'object') {
clone = {};
- for (var key in object) clone[key] = object.clone(object[key]);
+ for (var key in item) clone[key] = object.clone(item[key]);
return clone;
} else {
return item;
XHR "disconnect" method tries to call a none-existent _onClose() implementation, which is required to actually close the connection.
I'm bundling Socket.IO in a project of mine but don't want to have to bundle all of it (don't want to burden my users), I only want to bundle the files that are absolutely necessary. Is there anyway we can get a list of exactly what files Socket.IO needs publicly available to clients?
Like is it just socket.io.js and the web-socket-js flash file?
It used to go through LABjs but gimite's web-socket-js fails when injected dynamically in Safari.
I have the latest node, and I did a git pull recursive on the repository. Make hangs on the client tests, and when I use node to start the server, I'm served the chat.html file, but it hangs on connecting.
In my own code I can't get any of it to work:
http://github.com/draggor/GnuCard/blob/master/src/html/index.html
http://github.com/draggor/GnuCard/blob/master/src/js/mtg.js
http://github.com/draggor/GnuCard/blob/master/src/nodejs/server.js
I've have two distinct types of connections coming at my server - it would seem the easiest way to separate them would be to bind create two io.listeners and change the resource of each connection type - however in the current implementation in Listener.init
will just grab the last Listener bound to the server!
p.s Fantastic piece of software!
If a transport fails to connect (or times out, see #34), try the next on the list.
The test server currently doesn't run in Chrome, but runs perfectly on Firefox.
Some searching led to the discovery that websockets do not currently work in Chrome (June 22nd).
I'm not sure how to select which transports the client should try to use (i.e. "don't try with websocket").
There is either need for such a functionality, or a need for its documentation on http://socket.io/
โ
I keep getting this Javascript error on the Safari 4 debug console (iOS 4.1):
"Javascript Error on Line 1550
http:///www.mydomain.com/Socket.IO/socket.io.js
Flash player is not installed"
Is there any way to suppress this error in future releases of Socket.IO?
I realise that neither Flash nor WebSockets are supported on Safari iOS at the moment. I should add that XHR long polling works just fine!
Great project by the way!
I think this is just a packaging issue but the downloads for the client do not include the required SWF file in the lib/vendor/web-socket-js folder (the folder is completely empty).
I was able to find the SWF and the example chat files from that folder in the github source however but they probably need to be added to the download zip.
Upstream issue and fix details here: http://github.com/gimite/web-socket-js/issues#issue/31
Flagging here for inclusion if it gets accepted.
line 79 (or approximately) in jsonp-polling.js client side,
if (this._iframe.attachEvent){
should be changed to
if (!window.opera && this._iframe.attachEvent){
or complete will never trigger in opera so only first send will work.
It is never fired.
I'm getting a weird error with IE8/7 with Socket.IO. It appears that all the requests are returning 200 successful, but Node.js is claiming jsonp-polling is an illegal transport type.
http://stackoverflow.com/questions/3825271/socket-io-node-js-rails-3-ie
For WebKit browsers.
Separate Class from MooTools.
Why did I get seperate message on server side when I use socket.send('ok test')?
Here's the response on server side with sys.log(message);
17 May 03:06:56 - Initializing client with transport "websocket"
17 May 03:06:56 - Client 5388960442505777 connected
17 May 03:06:56 - [
17 May 03:06:56 - "
17 May 03:06:56 - o
17 May 03:06:56 - k
17 May 03:06:56 -
17 May 03:06:56 - t
17 May 03:06:56 - e
17 May 03:06:56 - s
17 May 03:06:56 - t
17 May 03:06:56 - "
17 May 03:06:56 - ]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.