3

I spend already 3 days for reading, watching tutorials about WebSockets, socket.io, node.js and so on. Basically, I'm a Laravel developer and have just a basic idea about all the rest components. With regret, after these 3 days I don't have in mind all logic step-by-step of implementing this architecture. I will try to explain what did I understand and you please correct me.

So :
WebSockets - is a bidirectional continuous connection between client and server. It uses another port, and basically it is not a HTTP/S connection.
For making this kind of app like I said, we need one more server, and idk why, but this is Node.js. At this Node.js server we should install socket.io (server-side package) and Redis.
Then, we need to add client-side socket.io (via CDN probably).
At Node.js server we are creating a server.js file where require all modules that we need, like socket.io and Redis. We open a connection for a specific non-used port (as 6001). Then we run this node server.
At front-end we are subscribe-ing to this channel and define method for emitting and listening to the server.

Example :
User1 is connecting to a specific route. User2 as well. User1 type a message for User2, when press Submit, message from User1 is sent to Node.js server, where it is sent in Redis(yes? if yes - Why?), and then Node.js is listening for what to do in this case, and send this message to specific user, or with broadcast to all users except the publisher.

Oh, it's even hard to explain that, too much steps and tehcnologies used. Can please someone correct my logic? I really want to understand all that process and logic of using this components. Or please, give me some useful articles and videos, may be I didn't saw them. Thanks!

1
  • guess your question in a little wide... Commented Feb 22, 2018 at 12:16

1 Answer 1

1

I suggest you read the official docs on how to build chat. Basically what you will have in the end is 2 servers, 1 for your Laravel app and the other for chat (Socket.io) . The key to this is using broadcasters and listening for events on both sides, frontend and backend.

Events are broadcast over "channels", which may be specified as public or private. Any visitor to your application may subscribe to a public channel without any authentication or authorization; however, in order to subscribe to a private channel, a user must be authenticated and authorized to listen on that channel.

Sign up to request clarification or add additional context in comments.

4 Comments

Oh, in Laravel 5.6 is already present documentation with Redis and socket.io. Thanks, hope I will have a better understanding after that.
I read it all, some new theoretical stuff, but anyway I am not feeling free to start develop something. At least I need a diagram with all tehcnologies used and how they works in combination. Do you know any good tutorials where it is all explained, how to launch a NodeJS server with that socket.io, and then how to integrate it all together with Laravel in a simple-demo application?
You don't need NodeJS server, you have Laravel Echo Server (github.com/tlaverdure/laravel-echo-server) with integrated support for Laravel..For technologies, you will need Laravel, Socket.IO, Laravel Echo and that's it
Laravel 5.6 documentation is quite confusing. I used this tutorial to get it work. Many different backend and frontend technologies need to work together, so its quite a high level. jplhomer.org/2017/01/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.