It is the first time for me working with Server Sent Events and probably I'm doing something wrong... I just followed a few guides and doing code experiments and locally everything seems to work fine.
Unfortunately when I upload the app on Heroku it doesn't work as expected.
The Javascript looks like this:
// SSE Start
// Check if SSE is supported
if (!!window.EventSource) {
var source = new EventSource('/live/redis');
} else {
console.log('SSE not supported');
}
source.addEventListener('open', function (e) {
console.log('Connection Open');
}, false);
I'm using NodeJS and Redis to get real time messages from the API, but it doesn't matter...
When the SSE connection is open I just print a log on the browser.
I do nothing else at moment and if I open my app locally it just work fine and I receive the console.log message.
If I push the project on Heroku I don't receive any open connection message.
I can not understand why, probably something is missing or probably do I need to configure Heroku to support SSE?
If I open the project with the command heroku local it works fine as well...
EDIT:
From the Heroku logs I receive this:
app/web.1: GET /live/redis 500 86.403 ms - -
I can not understand why, locally it is working fine, on Heroku it isn't.
The error is on my Node.js controller for the route /live/redis that start with this line:
// let request last as long as possible
req.socket.setTimeout(Infinite);
Changing it with the line below solved my problem:
// let request last as long as possible
req.socket.setTimeout(0x7FFFFFFF);
Now I don't know if it is the correct way, but for now it is working.
Related
It was working earlier (a few minutes before it stopped working) and now it just sits there with an open end attempting a connection. My console should print out "Ready" upon a successful start. However, it does not print anything out.
What I tried:
Reverting to an older commit that I know was functional.
Removing the proxy (I had to use a proxy because this bot is
connecting to an API that is white list only and I did not want to
send my personal IP).
Restarting my computer. Restarting CMD. Restarting VSCode.
Nothing worked.
Here is the basic structure.
bot.on('ready', () => {
console.log('Ready')
})
bot.login(token)
This is my console:
Command Prompt
EDIT: It works now, but it wasn't working earlier. Everything else on my computer was working (Chrome, Discord voice chat, VPN) except for the bot.
It may have run into an error. If you're not already handling errors, try listening for other events as outlined here:
bot.on('error', (e) => console.error(e));
bot.on('warning', (e) => console.warn(e));
bot.on('debug', (e) => console.info(e));
I've created a simple WebSocket server and am trying to connect to it with the following code:
function test(name) {
var ws = new WebSocket('ws://localhost:1234');
ws.onopen = function () {
ws.send('Hello from ' + name);
}
}
test('Edge');
This works fine from Chrome and IE11 on Windows10 but when I try from Edge, the onopen function isn't called, instead I eventually get the following error:
SCRIPT12029: WebSocket Error: Network Error 12029, A connection with the server could not be established
This is happening for version 12.10240 of Edge.
A similar problem was asked about here but the error message is different.
Things I tried:
IP - localhost, 127.0.0.1, the actual IP
Allow localhost loopback flag - both on and off
When trying to communicate with a different machine the problem does not occur.
Is this a defect in Edge or am I doing something wrong?
I had a similar problem, but it was when actually navigating to pages in the browser. I could use the phrase localhost and it worked fine, but I didn't work when I used my machine's name. I found this forum where they suggested that you run the following command in a administrator prompt:
CheckNetIsolation LoopbackExempt -a -n=Microsoft.MicrosoftEdge_8wekyb3d8bbwe
Worked for me. Thought you might be seeing some form of the same issue.
As the forum suggests, you can now also do this by opening Edge and navigating to "about:flags", then tick "Allow localhost loopback (this might put your device at risk)" under "Developer Settings". Should feel a little safer than pasting random stuff into your command prompt.
Edit: As tresf pointed out below, the loopback checkbox in the about:flags appears to have stopped working (as a fix), so you'll have use the CheckNetIsolation command, to make Edge exempt.
I fairly new to nodejs and I put the following code in some module,
module.exports = function (app) {
app.get('/aa', function(req, res) {
console.log("test");
debugger;
res.send('file updated');
...
the application is working and I see in the browser "file updated"
but I've two problems:
why don't I see "test" in the console?
I set up a debugger (using WebStorm 10) and it does not stop, what am I missing here?
I try also to run the debugger in Webstorm and click on debug and I see in the terminal Debugger listening on port 55236 but when I change the port in the browser nothing happen, any idea?
Node runs server side, so any console.log statements will appear in the the console you ran your script from. You won't see any debug statements in the browser except those from client js code. The reason you see file updated is because you sent that string as a response to your browser, and its simply spitting back the response it got.
Same thing with the debugger. If you are using your browser's debugger, it will only affect client js code, NOT your server code. Not too familiar with WebStorm, but they have instructions for debugging Node.js specific code here
If I generate an error inside the connection.onopen function, it does not get reported in the console when running using node:
connection.onopen = function (session) {
console.log('Connection opened');
throw('wobble');
console.log('Bye now..');
};
Console shows:
node autobahn_test.js
Connection opened
So any errors in the code are very difficult to spot.
I've searched mailing lists, read the API and have tried to read up about promises swallowing errors - as I've a feeling that's what's happening here. But no luck so far.
Can anyone tell me what I'm doing wrong?
Thanks
Mike
Setting gobal variable AUTOBAHN_DEBUG = true seeems to be the answer - thanks to the hint here
https://github.com/tavendo/AutobahnJS/issues/117
The Autobahn webpage only shows this for browswer side:
http://autobahn.ws/js/reference.html?highlight=debug#debug-mode
So keys seem to be (a) Global variable and (b) Before autobahn code is included.
Repeating my original example but with
AUTOBAHN_DEBUG = true;
I now see:
AutobahnJS debug enabled
trying to create WAMP transport of type: websocket
using WAMP transport type: websocket
Connection opened
Exception raised from app code while firing Connection.onopen() wobble
Which is exactly what I wanted
Hope this might help others.
Mike
I'm using autobahn 0.4.10 (https://github.com/oberstet/Autobahn) as a WebSocket server to send messages to a Google Chrome Extension. I am able to open and close connections using WebSocket(), but when I call autobahn.websocket.WebSocketServerProtocol.sendMessage() the message appears to be sent but isn't delivered until the connection is closed.
The api for WebSocketServerProtocol's sendMessage() (derived from WebSocketProtocol) can be found here: http://www.tavendo.de/autobahn/doc/python/websocketprotocol.html#autobahn.websocket.WebSocketProtocol
Has anyone experienced this problem before?
The code I have been on the client side is (js):
ws = new WebSocket('ws://localhost:4444');
ws.onmessage = function(event) {
console.log('hii');
}
And on the server (python)...
#json is a string object
def sendEvent(self, json):
print 'to', self.peerstr
self.sendMessage(json, sync=True)
Both Autobahn and my version of Chrome (17.0.963.46) appear (from what I've gotten out of the headers and docs) to use version 13 of the WebSocket draft protocol.
Turns out this was a threading problem with some threads block the twisted reactor.
See:
http://groups.google.com/group/autobahnws/browse_thread/thread/6bf0c43ec169efc3#
http://twistedmatrix.com/documents/current/core/howto/threading.html
Autobahn works with Chrome (tested up to v19 .. Canary).
Could you try the
https://github.com/oberstet/Autobahn/blob/master/demo/broadcast/broadcast_server.py
demo to see if you have a general issue?
If that runs, direct your extension to that demo server .. it'll send you 1 tick per sec.
You can also enable debug output by changing the factory line to code like this
https://github.com/oberstet/Autobahn/blob/master/demo/echo/echo_server_with_logging.py#L50
2 more notes:
you don't need the sync = True option (it's really an advanced option .. mostly used with the Autobahn WS testsuite)
you might wanna join http://groups.google.com/group/autobahnws .. get answers more quickly .. I discovered your Q only by accident here
Disclosure: I am author of Autobahn and work for Tavendo.