I have created a socket server in Node js. It is working fine while subscribing from an ejs file.
The part I'm confused is how do I keep my laravel application listening to the server I have created?
Thanks in advance.
Laravel community already come up with a solution and it's call Laravel Echo Server (Check that out) that basically just a Node + socket.io that implement all the pub/sub logic for your Laravel app.
If you want to take complexity into your own hand then you could try setting up broadcasting driver in Laravel to use Redis. In simple term, Redis is the middleman that connect your Laravel app to your socket.io app for websocket connection. This is call message broker.
For example, you have Laravel app listening and publishing event on a Redis server and Node + Socket.io server doing the same thing. When you fire an event through Laravel, your node will able to listen to that event too through Redis acting as a broker. Your node then can instruct Socket.io to do whatever it want with its front-end user.
This solution doesn't require Laravel-echo but you need to do a lot of stuff for authentication, handling private channel and presence channel .. etc.
I suggest you take a look into Laravel Echo Server as what I've describe is only scratching the surface.
Related
I having some doubts that:-
what is need to use the socket.io client we can use only the socket.io server to stop refreshing the app.
what is different between the socket.io client and socket.io server.
check this link
socket-io.client is the code for the client-side implementation of socket.io. That code may be used either by a browser client or by a server process that is initiating a socket.io connection to some other server (thus playing the client-side role in a socket.io connection).
A server that is not initiating socket.io connections to other servers would not use this code. This has been made a little more confusing that it probably should be because when using socket.io, it appears that both client and server are using the same socket.io.js file (because they both refer to a file with the same name), but is not actually the case. The server is using a different file than the client.
From the Github page for socket-io.client:
A standalone build of socket.io-client is exposed automatically by the socket.io server as /socket.io/socket.io.js. Alternatively you can serve the file socket.io.js found at the root of this repository.
Keep in mind that there are unique features that belong to client and server so it should not be a surprise that they use some different code. Though they share code for parsing the protocol and things like that, the server has the ability to run a server or hook into an existing web server and it has methods like .join() and .leave() and data structures that keep track of all the connected sockets and is expected to live in the node.js environment. The client has the ability to initiate a connection (send the right http request), do polling if webSockets are not supported, build on a native webSocket implementation if present, etc....
I'd like to make a app with React-Native that's accept connections from another devices (Desktops or mobiles) through raw tcp sockets (like node's Net API) or WebSockets (like Socket.io). The point is that, socket server must be running on the React-Native's App.
I already tried Socket.io and react-native-tcp, it works when i make the server run on a nodeJS's application and the client on RN's app, but not the reverse.
When i try to import Socket.io and make it listen on a port, a error is raisen, because RN don't have node's http module. Just Socket.io/clients works.
I think that i'm doing something wrong, but is really possible to do that? and what is the best way?
Obs: I'm really new in RN's world.
No, we can't create a server although if we create a server we can't connect any other external applications to the server.
So create a server and deploy it in any could service then use it in your react-native app.
I try to make a client-server app with socket.io.
Socket.io server seems work but the client cannot connect to it. The error i get is about the '/socket.io/socket.io.js' like what it is unable to load it.
So here are my questions
is it mandatory to have server and client in the same folder as we can see in the official demo ?
can we make a nodejs socket.io server without express ?
Depending on how your project is setup, you need to create 2 server files, 1 for the app, and one for the websockets, and every time a user opens the app it should open(and be told where to try and open the connection) a connection to the websockets server. On my websockets apps I have the app running on localhost:3000, and websockets server on localhost:3001 (and tell the app to look for a server on 3001), so really you don't need to have the server files in the same folder, they can be in 2 opposite ends of your computer, as long as the app points to the server, then your fine, once a connection has been opened, the websocket server will see the client, and it should work! Let me know if that make sense.
No, you can download socket.io front-end lib from another sources, for example cdn. Be sure you installed the right version.
Yes, you can make it without express. Express is just another option for creating an socket.io server.
For example, currently in my project that is written in another back-end node framework i'm using the code below to establish the socket.io server.
const io = require("socket.io")(2337);
io.on("connection", socket =>
// some code
)
I fixed the problem of websocket communication between my server and my client.
After inspected my html client file, i saw on the console this error message 'ReferenceError: io is not defined'.
I google that error and i found this.
I have the following setup:
(1) Node.js server connects to another api via websocket. This api provides an onChange behavior that can be listened to.
(2) Angular frontend calls api from Node.js server (which in turns call websocket api as stated in #1).
How can frontend be aware of the onChange behavior that the Node.js server is listening to?
Use Emitter Service in Angular,whenever node server receive changes it should emit from node and angular should be able work on written logic
I'm wondering how I can connect to a socket.io websocket server externally. I've been using wscat to test connections but to no avail. The code I'm using is here. Anyways, I've tried wscat'ing to where I deployed it, which is c9, but that hasn't worked. I've recieved an ECONNREFUSED error from wscat. Is there a specific thing I need to do to enable socket.io connections from outside of a page hosted on the same server? The end game is to be able to connect to the socket.io server with an iOS app.
Thanks
You must use a Socket.IO library for your language. Socket.IO is not plain websockets and cannot be used as such.
Instead, look at something like: https://github.com/pkyeck/socket.IO-objc