You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.
I raised the socketToMe event on the server router, but I did not receive it from the client.
The server was working properly after raising the connection event and adding the following code inside it:
Is it correct to work without the connection event?
[router code]
varexpress=require('express');varrouter=express.Router();/* GET users listing. */router.get('/',function(req,res,next){res.io.on('connection',function(socket){// 클라이언트로 news 이벤트를 보낸다.socket.emit('server-news',{hello: 'world'});// 클라이언트에서 my other event가 발생하면 데이터를 받는다.socket.on('client-news',function(data){console.log(data);});});res.render('users',{title: 'Express'});//res.send('respond with a resource.');});module.exports=router;
[client code]
<scriptsrc="../socket.io-client/dist/socket.io.js"></script><script>// localhost로 연결한다.varsocket=io.connect('http://localhost:3000');socket.on('server-news',function(data){console.log(data);//서버에 my other event 이벤트를 보낸다.socket.emit('client-news',{my: 'data'});});</script>
The text was updated successfully, but these errors were encountered:
Hi! @brianjhanson
I am studying English. so it is difficult to explain.
I am using a Google Translator.
I have not worked with the sample code below.
but, But this worked because I did this. router.get('/', function (req, res, next) { res.io.on('connection', function (socket) { socket.emit('socketToMe', 'users'); res.send('respond with a resource.'); }); });
I hope it has been well explained to you.
thank you.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I raised the socketToMe event on the server router, but I did not receive it from the client.
The server was working properly after raising the connection event and adding the following code inside it:
Is it correct to work without the connection event?
[router code]
[client code]
The text was updated successfully, but these errors were encountered: