Reputation: 3138
I have a question about streaming an audio file via a NodeJS server. I'm using the following code:
var http = require('http');
var fs = require('fs');
var filePath = 'media/test.mp3';
var stat = fs.statSync(filePath);
http.createServer(function(request, response) {
response.writeHead(200, {
'Content-Type': 'audio/mpeg',
'Content-Length': stat.size
});
fs.createReadStream(filePath).pipe(response);
})
.listen(3000);
It does work when I ...
But it does not work when I ...
By not working, I mean I can see a pending request ("request is not finished yet!") in Chrome devtools, but the stream sometimes starts only for less than a second, sometimes it doesn't start at all. In the devtools I can see that only 4 KB are loaded (on localhost it's 3.1 MB).
To enable the access from outside, I configured port forwarding on my router, so that requests to port 3000 are forwarded to my computer's internal IP.
For other things than streaming my setup is working, so for example it is possible to call REST routes defined on the server.
EDIT:
Meanwhile, I also tried to do the streaming with PHP instead of NodeJS. But it shows exactly the same behaviour.
Do you guys have an idea what could be the reason? Thank you!
Upvotes: 1
Views: 1052
Reputation: 3138
Yesterday, I finally was able to test the exact same setup but with a different router (FritzBox 7320) -- and everything worked as it should. So there must be problems with the router I'm using at home (o2 HomeBox 6441).
I think the best will be trying to get some support in the manufacturer board.
Thanks for your effort anyways!
Upvotes: 0
Reputation: 1281
Looks like some configuration issue with setting up port forwarding in router as you have tried with two different code bases.
If you are doing only for testing you can use localtunnel to expose your localhost
to publicly over the internet
.
There are few other alternatives also like ngrock or forwardhq.
Hope it helps.
Upvotes: 0