I have a 3rd party server that runs SignalR. In order to connect to that server and read messages i have created a javascript code that should run from NodeJS on ec2 (Linux) instance. The issue is that when i try running my code that only connects to the server i'm getting this error:
.....node_modules/signalr/jquery.signalR.js:1085
}(window.jQuery, window));
^
ReferenceError: window is not defined
What kind of window? I have an ssh-only linux server? My existing JS code is this:
const signalR = require("signalr"); //here i can't use #aspnet/signalr or #microsoft/signalr because those aren't compatible with SignalR that's on the 3rd party server. UGH Microsoft!
let connection = new signalR.HubConnectionBuilder().withUrl("https://myurl/signalr/hubName")
.configureLogging("warn")
.build();
connection.start().then(() => {
console.log("yeeey!");
}).catch((e) => {
console.log(e);
});
What are my options here in order to run this? I have installed NodeJS on ec2 instance using official Amazon tutorial so it should be the latest current version - 13.2
Found a solution.... This library solved my problems
Please write this:
import * as signalR from '#aspnet/signalr';
Related
The following code only works in the browser. It does not work in node.js
let socket1 = io('http://localhost:3031/nsp')
socket1.on("connect", (error) => {
console.log("socket1: connect")
});
I am connecting to a netty-socketio (v1.7.7) java server. I am able to connect to the root namespace on both browser and node.js clients and everything works as expected. However, if I try to connect to a namespace, only the browser client can connect as expected.
Furthermore, I can see on the server that the node.js client (v2.4.0) is connecting to the root namespace when it should be connecting to the named namespace "nsp". As such, the clients join the root namespace and seemingly never join the "nsp" namespace.
On further inspection, the only event I can get to fire on the node.js client, when specifying a namespace, after connecting is "ping" all other events (connect,connect_error,error,reconnect...) never trigger.
Update: the above code works when connecting to a node.js server, so the issue appears to be with the netty-socketio server.
Here is how the netty server is initialized:
Configuration config = new Configuration();
config.setHostname("localhost");
config.setPort(3031);
server = new SocketIOServer(config);
server.addNamespace('/nsp')
I finally figured it out. I had to revert the node.js client version to 1.7.4 (https://www.npmjs.com/package/socket.io-client/v/1.7.4) to get it to work. Not sure why I was forced to use such an old client to be able to use namespaces.
I am trying to set up Angular 5 project in Electron and also run nodejs in server side, i know that electron permit to create desktop app, but is it possible to create server side app with electron, also i'm not sure if it's possible to have the nodejs app and angular all in the same project with ngx electron.
If I understand you correctly, you want a desktop application that in some way also communicates with a server.
Sure, that's possible since Electron will bundle node.js in the generated binary.
The easiest way I can think of is setting up an HTTP API (e.G REST) on your server side (possible with any language, I'd recommend either PHP or Node.js) and use http in your ng/electron app to talk to the server.
http.get(options, (res) => {
// Do stuff
}).on('socket', (socket) => {
socket.emit('agentRemove');
});
I am using Neo4j database as graphenedb on Heroku connecting using Ember.js framework. The application is being run locally through Node.js (Not being run through Heroku server).
On a call to driver.session(); I receive this error:
WebSocket connection to 'ws://hobby-blablabla.dbs.graphenedb.com:24786/' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
I import driver using ember-browserify:
import Neo4j from 'npm:neo4j-driver';
I call the code:
var neo4j = Neo4j.v1;
var driver = neo4j.driver(graphenedbURL, neo4j.auth.basic(graphenedbUser, graphenedbPass));
var session = driver.session(); // error it thrown here
I retrieved the connection infos using Terminal commands with Heroku CLI like: heroku config:get GRAPHENEDB_BOLT_URL
Chances are that Heroku doesn't actually allow me to connect to the database from my local machine. But it would be really nice to work around this issue and be able to connect. Thank you for help.
I'm Judit from GrapheneDB. If I understood you well, you're loading the Neo4j javascript driver in your Ember.js application and the driver is trying to connect to GrapheneDB database via WebSocket. Unfortunately this is something we don't support.
We always recommend to add to your stack a backend, that deals with the connection to GrapheneDB, and avoid doing it from the browser and prevent exposing your credentials to anybody using your app. You can build a Node.js server and manage the driver connections there using the same driver you are using now (npm install neo4j-driver).
BTW, you should be able to connect to your database from your local machine using the values of your Heroku environment variables. You can easily check by running:
GDB_URL=`heroku config:get GRAPHENEDB_URL`
curl -v $GDB_URL
I believe you need to set CROSS setting. Not sure how to do so in Node, but following is what I did to set my Rails app,
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*', headers: :any, methods: [
:get, :post, :put, :patch, :delete, :options, :head
]
end
end
OK this is very simple to anyone who's used websocket and nodejs.
I have created a websocket server named ws_server.js and put it in C:\Program Files (x86)\nodejs where I have installed the nodejs framework. I started the server and it is running and it says it's listening on port 8080. So far so good, I have the server running.
Now I simply want to connect to it from client code so that I can do all that lovely stuff about capturing events using event listeners etc. The problem is, embarassingly, I cannot figure out what URL to use to connect to my websocket server.
function init() {
testWebSocket();
}
function testWebSocket() {
websocket = new WebSocket("ws://localhost:8080/"); // WHAT URL SHOULD BE USED HERE?
websocket.onopen = function(evt) { alert("OPEN") };
websocket.onclose = function(evt) { alert("CLOSE") };
websocket.onmessage = function(evt) { alert("MESSAGE") };
websocket.onerror = function(evt) { alert("ERROR") };
}
function doSend(message) {
// this would be called by user pressing a button somewhere
websocket.send(message);
alert("SENT");
}
window.addEventListener("load", init, false);
When I use ws://localhost:8080 the only events that trigger are CLOSE and ERROR. I cannot get the client to connect. I must be missing something very simple. Do I need to set up my nodejs folder in IIS for example and then use that as the URL?
Just to reiterate, the websocket server is running fine, I just don't know what URL to use to connect to it from the client.
EDIT: The websocket server reports the following error.
Specified protocol was not requested by the client.
I think I have got it working by doing the following.
var websocket = new WebSocket("ws://localhost:8080/","echo-protocol");
The problem being that I needed to specify a protocol. At least now I get the onopen event. ...if nothing much else
I was seeing the same error, the entire web server goes down. Adding the protocol fixes it but leaves me wondering why it was implemented this way. I mean, one bad request should not bring down your server.
You definitely have to encase it a try/catch, but the example code provided here https://www.npmjs.com/package/websocket (2019-08-07) does not. This issue can be easily avoided.
I just wanted to share a crazy issue that I had. I was able to connect to a websocket of an old version of a 3rd party app in one computer, but not to a newer version of the app in another.
Moreever, even in new computer with the new version of the app, The app was able to connect to the websocket, but no matter what I did, when I tried to connect with my own code, I kept getting the error message that the websocket connection failed
Long story short, They changed an apache configuration that allowed connecting to the websocket via a proxy.
In the old version, apache config was:
ProxyPass /socket/ ws://localhost:33015/ retry=10
ProxyPass /socket ws://localhost:33015/ retry=10
In the new version, apache config was changed to:
ProxyPass /socket/ ws://localhost:33015/ retry=10
By bad luck, I was trying to connect to ws://localhost/socket and not to ws://localhost/socket/. As a result, proxy was not found, and connection returned an error.
Moral of the story: Make sure that you are trying to connect to a websocket url that exists.
For me, the solution was to change the URL from ws:// to wss://. This is because the server I was connecting to had updated its security, and now only accepted wss.
Iam working on node.js chat application, i've hosted the node.js on IIS in windows.
my intention is to include the node.js in Asp.net mvc as explained by Jon Galloway for performing chatting( text, audio ,video ) in asp.net web application.
my Installation details:
iisnode.js - iisnode-full-iis7-v0.2.3-x86
node.js - node-v0.8.19-x86
express.js version - 3.1.0
socket.io version - 0.9.13
on windows 7 32 bit system with IIS 8.0 express
I've successfully hosted the node.js on IIS, and run the samples
But when i start coading socket.io i got stuck..
when i start connecting with client browser to server, i got an error at client browser saying
Uncaught TypeError: Cannot call method 'onClose' of null socket.io.js:1771
In my server app iam using socket.io configuration as
io.configure(function () {
io.set('transports', [
'xhr-polling'
, 'jsonp-polling'
]);
io.set("polling duration", 10);
if (process.env.IISNODE_VERSION) {
io.set('resource', 'node/socket.io');
}
});
Is this issue related to versions iam using (express, and socket.io node.js) Or in my coading, any idea about the issue please help me.
thank you.
I think it's because you didn't set the resource path in the client socket.io configuration.
socket = io.connect('http://myurl/node/socket.io', { resource : 'node/socket.io' })