Socket.IO

No messages received in SocketIO4net

扶醉桌前 提交于 2019-12-24 12:38:28
问题 I am attempting to consume a socket.io API using SocketIO4net however cannot seem to receive any messages. In the same VS2010 solution, I have a website with the following code: <script src="https://api.icbit.se/socket.io/socket.io.js"></script> <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script> <script> $(document).ready(function () { var conn = io.connect('http://api-url'); conn.on('connect', function () { alert('Connected'); conn.emit('message', { op:

Any ideas how to create parameterised streaming api?

坚强是说给别人听的谎言 提交于 2019-12-24 12:15:45
问题 I want to create parameterised streaming api like http://dev.twitter.com/pages/streaming_api_methods#statuses-filter The straightforward way I see is following: Create redis channel for messages (like twitter statuses). Each connected socket subscribes on this channel. Inside redis callback each sockets check if current message fits supplied parameters (parameters could be set as separate socket message) What you think guys? 回答1: You might want to look at nats 来源: https://stackoverflow.com

Replace an object item in object list with another item

南楼画角 提交于 2019-12-24 11:50:36
问题 I have an object of items in my variable this.rows . There is a real-time item coming from the server which is identical to one which is inside in this.rows object collection. How to I replace an item with a new values ? Here is an example: let rows = [ {id: 11, active: 'no'}, {id: 22, active: 'yes'}, {id: 33, active: 'no'}, {id: 44, active: 'no'} ] new_item = {id: 22, active:'yeah'}; rows.forEach(item => { if (item.id === new_item.id) { return new_item; } }); 回答1: Use the "findIndex" method

socket.io on mobile - does not disconnect on device sleep, close browser, change tab

回眸只為那壹抹淺笑 提交于 2019-12-24 11:41:53
问题 I have a basic Socket.io implementation using NodeJS with Express server. (Basically the Get Started example on Socket.io web site) On desktop it connects/disconnects as expected. When you browse to the page the socket connects. Connection events are fired both on the client and server side. And she the user closes the browser, the socket disconnects. But on mobile the disconnect does not work as expected. When you browse to the page the socket connects, and events are fired. But the socket

Too many on-connection events with Socket.io, does it hurt?

不打扰是莪最后的温柔 提交于 2019-12-24 11:35:01
问题 I have an application using node.js where multiples objects has a reference to socketio implementation. Every one of them opens an on-connection event in order to add their particular events to the socket connection, like this: this.io.on('connection', function(socket){ socket.on('subs', function(sub){ self.processSub(sub); }); // more events }); I have like 10 of these objects and the idea is to keep adding modules using this architecture. My question is: Does socket.io is designed for this

Mongoose query for connected friends

别等时光非礼了梦想. 提交于 2019-12-24 11:33:51
问题 how can i effecively display the status 'connected user' on my Friends list using mongoose ? am using socket io too (and i plan to switch to socket p2p) my friend list is an array of objects with uid , name , pic , socket as props and this array is stored in my profile document. i see a couple of options here but can't figure out what's best use the operator $in to query all the users connected to the app and match the result with my array of friends store every logged in user in a separate

Socket.io Client Request Origin URL

心不动则不痛 提交于 2019-12-24 11:29:29
问题 On the client, in the browser, I have this code: this.socket.on('initial', function(data) { console.log(data); }); On the server I have: socket.sockets.on('connection', function(client){ console.log('client connected'); }); My question is: how can I detect the URL where the request came from? For example if the first closure was running on "/posts/view/1", I want to be able to detect it inside of the second closure. 回答1: You could send this data back to the server. A little hand-wavey on the

Setting up dynamic chat rooms in FlaskSocketIO chat

孤者浪人 提交于 2019-12-24 10:48:43
问题 I want to let user's of my mini chat to create their rooms dynamically. For now i got const in flask server app: # Predefined rooms for chat ROOMS = ["Lounge", "news", "games", "coding", "food", "cars"] And user join/leave routes are in flask: @socketio.on('join') def on_join(data): username = data["username"] room = data["room"] join_room(room) # Notofication about new user joined room send({"msg": username + " has joined the " + room + " room."}, room=room) @socketio.on('leave') def on

Cannot read property 'socket's of undefined when exporting socket.io

你说的曾经没有我的故事 提交于 2019-12-24 10:46:53
问题 I'm trying to modularize my application and would like to emit different event to client on different js file. Sample code below shows that an event 'onlinestatus' will be fired from led.js. However I keep on getting the message 'Type Error: Cannot read property 'sockets' of undefined' whenever I try to emit the event from led.js. I suspect something could be wrong when I"m trying to export the io from /bin/www. /bin/www var server = http.createServer(app); var io = require('socket.io')

React Hooks & UseEffect not updating display with socketIO data. Only renders elements in array

女生的网名这么多〃 提交于 2019-12-24 10:44:52
问题 import React, {useState, useEffect} from 'react'; import socketIO from 'socket.io-client'; import Container from 'react-bootstrap/Container'; function Sock() { const [textData, setTextData] = useState([]); useEffect(() => { const socket = socketIO('http://127.0.0.1:5009'); socket.on('chat message', (text) => { setTextData([ textData.push(text) ]); console.log(textData); }); },[]); return ( <Container> <h1>Socket</h1> {textData.map((text) => <li>{text}</li>)} </Container> ); } export default