Web socket connection failed after deploying in AWS - node.js

I'm working on frontend development using react. Backend is developed using node js.
In our application, we have web socket implemented in it. We are able to establish websocket connection and load server messages whenever it's used locally. (ws://localhost:portNo)
But, the problem is once after the code is deployed in aws,we're not able to establish the web socket connection.
Please suggest some ideas. It would be more helpful.
Thanks in advance!!!

Related

Socket.io, Unreal, & Heroku (Node js) : Client not connecting to server?

I'm currently working on a game that connects to a Node.js server for multiplayer data.
The game is developed in Unreal Engine 4 and uses the Socket.io plugin to connect to the Node.js server (cors, express being used).
Everything works locally. So now I'm trying to move on to hosting the server remotely and connecting the unreal client to the remote Node.js server.
I looked into Heroku and set myself up, everything is working fine on its end to my knowledge - I created a tester page with a success message when you load the URL and that comes through.
My first question is - what am I doing wrong when I use unreal to point the socket.io plugin to the server url?
The socket.io plugin asks for a port #, I've tried the following:
http:/{my server/heroku url}:8080/
http:/{my server/heroku url}:3000/
http:/{my server/heroku url}:18279/ (which was given to me by Heroku).
http:/{my server/heroku url}/
So far the game does not connect to the deployed server, the way it does locally.
Any suggestions on what could be going wrong/what am I failing to do next?
A few things after researching:
I do have http-session-affinity enabled
Since the server is working locally, I'm going to make the assumption that the deployed code is not the issue, and that it has to do with the way I'm trying to connect.
is it possible that I have further authorization to config? Such as allowing the unreal game/client to connect to the server/that the client is being blocked some how?
I figured out the issue, it had to do with how my Node.js server code was calling socket.io.
If you come across this issue please send me a message or comment here and I will be happy to send you the code that worked.

client-server websocket

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.

Google Cloud Messaging XMPP Server with Node.js

Title is fairly self explanatory. I need to create an XMPP server in Node.js to communicate with Google Cloud Messaging. The XMPP connection should allow me to send messages from the server to the client (Android app) and also from the app back to the server without the app needing a seperate socket connection to the server (all messages routed through GCM. Could anyone perhaps guide me in the right direction?
P.S. If I have provided insufficient information please let me know :)
It seems that a simple Google search return that there is an XMPP server developed in NodeJS: https://github.com/node-xmpp/node-xmpp-server
This is likely what you want to deploy.

Need help http Server and client server

I have used an application for login, adding friends and chat using node.js and mongoDB.I installed the node.js and monogoDB on ec2 instance. However, I do not know if need to use client server and http server?
Here is the application that I used https://github.com/1karthik/Node.js_UserLogin_Template
note: I am new to node.js and mongoDB
you dont need a "client server". Your http server will serve to your clients some javascript files that will help them to comunicate with your server. If you go in app/public/scripts you can see theese files.

Socket.io Not Connecting

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

Resources