Giter Club home page Giter Club logo

Comments (6)

epixa avatar epixa commented on June 22, 2024

@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.

remon avatar remon commented on June 22, 2024

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.

remon avatar remon commented on June 22, 2024

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 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.

epixa avatar epixa commented on June 22, 2024

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.

remon avatar remon commented on June 22, 2024

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.

epixa avatar epixa commented on June 22, 2024

In that case, you would need to implement a solution for that manually.

from chuckt.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.