Comments (6)
@remon Sorry for the delay in getting back to you.
At the moment, chuckt doesn't have a built-in equivalent to the socket.io broadcast
functionality that allows the server to send out events to all socket connections at once. In the absence of this functionality, you could do something like:
var chuckts = {};
function broadcast() {
var args = arguments;
Object.keys(chuckts).forEach(function(connid) {
var chuckt = chuckts[connid];
chuckt.emit.apply(chuckt, args);
});
}
sock.on('connection', function(conn) {
var chuckt = new ChuckT(conn);
chuckts[conn.id] = chuckt;
broadcast('new-client-connected'); // emits "new-client-connected" to all clients
conn.on('close', function() {
delete chuckts[conn.id];
});
});
In this example, the broadcast function would proxy all arguments directly to the emit call on all sockjs connections.
Note that the behavior of broadcast()
in this example is slightly different than socket-io in that it would emit the event to all clients including the current client. The broadcast function could be altered to take in an option "chuckt" object as the first argument and exclude the corresponding connection if present.
Also please beware, the above code is entirely untested.
I hope this helps!
from chuckt.
Thanks dear for your response ..I will test it and tell you how it's
working ..I was using socket.io for more than 6 months ..but i found its
not working with many users ...and then I read about its drawbacks with Avs
and firewalls ..thanks again
2013/10/25 Court Ewing [email protected]
@remon https://github.com/remon Sorry for the delay in getting back to
you.At the moment, chuckt doesn't have a built-in equivalent to the socket.io
broadcast functionality that allows the server to send out events to all
socket connections at once. In the absence of this functionality, you could
do something like:var chuckts = {};function broadcast() {
var args = arguments;
Object.keys(chuckts).forEach(function(connid) {
var chuckt = chuckts[connid];
chuckt.emit.apply(chuckt, args);
});}
sock.on('connection', function(conn) {
var chuckt = new ChuckT(conn);
chuckts[conn.id] = chuckt;broadcast('new-client-connected'); // emits "new-client-connected" to all clients
conn.on('close', function() {
delete chuckts[conn.id];
});});In this example, the broadcast function would proxy all arguments directly
to the emit call on all sockjs connections.Note that the behavior of broadcast() in this example is slightly
different than socket-io in that it would emit the event to all clients *
including* the current client. The broadcast function could be altered to
take in an option "chuckt" object as the first argument and exclude the
corresponding connection if present.Also please beware, the above code is entirely untested.
I hope this helps!
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-27120225
.
from chuckt.
its working ..one last question how can you implement something like
socket.set and socket.get with sockjs and chuckt.js ?
2013/10/25 Remon torremolinos [email protected]
Thanks dear for your response ..I will test it and tell you how it's
working ..I was using socket.io for more than 6 months ..but i found its
not working with many users ...and then I read about its drawbacks with Avs
and firewalls ..thanks again2013/10/25 Court Ewing [email protected]
@remon https://github.com/remon Sorry for the delay in getting back to
you.At the moment, chuckt doesn't have a built-in equivalent to the socket.io
broadcast functionality that allows the server to send out events to all
socket connections at once. In the absence of this functionality, you could
do something like:var chuckts = {};function broadcast() {
var args = arguments;
Object.keys(chuckts).forEach(function(connid) {
var chuckt = chuckts[connid];
chuckt.emit.apply(chuckt, args);
});}
sock.on('connection', function(conn) {
var chuckt = new ChuckT(conn);
chuckts[conn.id] = chuckt;broadcast('new-client-connected'); // emits "new-client-connected" to all clients
conn.on('close', function() {
delete chuckts[conn.id];
});});In this example, the broadcast function would proxy all arguments
directly to the emit call on all sockjs connections.Note that the behavior of broadcast() in this example is slightly
different than socket-io in that it would emit the event to all clients *
including* the current client. The broadcast function could be altered
to take in an option "chuckt" object as the first argument and exclude the
corresponding connection if present.Also please beware, the above code is entirely untested.
I hope this helps!
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-27120225
.
from chuckt.
The set/get functions in socket.io aren't really related to websockets at all, they're just an extra feature that was added to that library. If you're using the default MemoryStore backend for set/get in socket.io, then you could always just add whatever properties you want directly to the chuckt object.
If you're using a different store (e.g. redis), then its more complicated, and there is no built in solution to chuckt or sockjs.
from chuckt.
I am using socket.io get and set to handle user id ,so when user open I
retrieve some data from redis using his id and also when he close the
connection
2013/10/27 Court Ewing [email protected]
The set/get functions in socket.io aren't really related to websockets at
all, they're just an extra feature that was added to that library. If
you're using the default MemoryStore backend for set/get in socket.io,
then you could always just add whatever properties you want directly to the
chuckt object.If you're using a different store (e.g. redis), then its more complicated,
and there is no built in solution to chuckt or sockjs.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-27173447
.
from chuckt.
In that case, you would need to implement a solution for that manually.
from chuckt.
Related Issues (3)
- CommonJS support HOT 6
- Tests
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chuckt.