When to connect and disconnect to socket.io

Asked 2 years ago, Updated 2 years ago, 66 views

Hello! I am a student studying nodejs.

I have a nodejs server that uses socket.io

Web application is running at the front desk.(reactJS/redux)

It's because I don't have enough knowledge about Socat

First of all, one of my web application functions is chatting function using Socat

In addition, basic http communication is the main function.

First of all, I thought I didn't need to connect with socket.io unless I went into url in the chat room.

When do I usually have to connect in this case? Can I connect the moment I enter the chat room url?

Also, do you usually disconnect when you leave the chat room after the chat starts (when you go to url other than chatting)?

I heard somewhere that the process of building a socat is extreme. Mostly in situations like this

I wonder when you need to connect and disconnect separately.

I'd appreciate it if you could answer!

socket.io node.js

2022-09-21 15:58

1 Answers

As you said, you just need to connect when you enter the chat room.

When you call the io.connect() function in JavaScript, it becomes connect, so

You can call io.connect only on the page with the chat function

Simply put, you can only call the socket.io JavaScript file and the event script you wrote yourself on that page.

When you close or move the page, it automatically becomes disconnect


2022-09-21 15:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.