socket.io-stream facing 404 issue when accessing in socket client and server also









up vote
2
down vote

favorite












I was trying to create an mp3 stream (already added the .mp3 file in my machine) using socket.io-stream and access it using the client.html file.



After installing the socket.io-stream with npm and started, getting the below error in chrome console:




http://localhost:5001/socket.io-stream/socket.io-stream.js net::ERR_ABORTED 404 (Not Found)




and




Uncaught ReferenceError: ss is not defined




Here is my client.html file:






<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>bb</title>
</head>

<body>
<script src="/socket.io/socket.io.js"></script>
<script src="/socket.io-stream/socket.io-stream.js"></script>
<h1>Audio Testing 1 2 3</h1>
<audio id="audio" controls>
<source src="" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<br>


<script>
var socket = io('http://localhost:' + window.location.port);
var audio = document.getElementById('audioSource');
console.log("hoi");
socket.on('start', function (data)
console.log("start");
console.log(data);
// socket.emit('my other event', my: 'data' );
socket.emit('stream', my: 'data' );
console.log("");
ss(socket).on('audio-stream', function(stream, data)
parts = ;
console.log("DATA -->> ")
stream.on('data', (chunk) =>
console.log(chunk);
parts.push(chunk);
);
stream.on('end', function () );
);
);
</script>
</body>
</html>





Here is my server.js file






var express = require('express');
var app = express();
var server = require('http').Server(app);
var fs = require('fs');
var io = require('socket.io')(server);
var ss = require('socket.io-stream');

app.use(express.static(`$__dirname/html`));

server.listen('5001');

app.get('/', function (req, res)
res.sendFile(__dirname + '/index2.html');
);


io.on('connection', function (socket)
socket.emit('start', hello: 'world' );
socket.on('stream', function (data)
console.log(data);
var stream = ss.createStream();
var filename = __dirname + '/audio/musicfile.mp3' ;
ss(socket).emit('audio-stream', stream, name: filename );
fs.createReadStream(filename).pipe(stream);
);
);





Also please suggest any pointers (latest tutorials/articles related to socket audio streaming).










share|improve this question



















  • 1




    Quick question do you have the file socket.io-stream.js located in your public directory so it is accessible at the url: localhost:5001/socket.io-stream/socket.io-stream.js ? does it work if you use "cdnjs.cloudflare.com/ajax/libs/socket.io-stream/0.9.1/…" instead?
    – Lagoni
    Nov 10 at 19:52










  • @Lagoni That worked(When using the cdnjs link.). Thanks. However, moving forward with the requirement, when I'm getting the mp3 file played in my windows machine when accessing the url: localhost:5001 , why am I not able to play the file in mobile connected to 192.168.x.x:5001/ when both are in same LAN. I can see the html file loaded with audio controls, but unable to hit the play button. Any suggestions?
    – beta programmers
    Nov 10 at 21:36







  • 1




    My guess is the var socket = io('http://localhost:' + window.location.port); it then tries to access the socket locally, on your phone. Which is not where your socket server is located :) I believe you can just say var socket = io(); since your socket server is located on the same port as your express server.
    – Lagoni
    Nov 10 at 21:47










  • Guess worked right. Now, able to get this working mobile as well. When I'm hitting the url in mobile, I was expecting the mp3 file to continue from a certain point of song length. I can use a method similar to audio.setPosition and then play, however, I'm trying a solution similar to icecast live streaming approach. Can we do this using sockets?
    – beta programmers
    Nov 10 at 21:59










  • Unfortunately i do not have any experience with either icecast or socket.io-stream, but i know that createReadStream have an option called start and end where you can specify where to read from and to. Hope that can guide you in the right direction :)
    – Lagoni
    Nov 10 at 22:05














up vote
2
down vote

favorite












I was trying to create an mp3 stream (already added the .mp3 file in my machine) using socket.io-stream and access it using the client.html file.



After installing the socket.io-stream with npm and started, getting the below error in chrome console:




http://localhost:5001/socket.io-stream/socket.io-stream.js net::ERR_ABORTED 404 (Not Found)




and




Uncaught ReferenceError: ss is not defined




Here is my client.html file:






<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>bb</title>
</head>

<body>
<script src="/socket.io/socket.io.js"></script>
<script src="/socket.io-stream/socket.io-stream.js"></script>
<h1>Audio Testing 1 2 3</h1>
<audio id="audio" controls>
<source src="" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<br>


<script>
var socket = io('http://localhost:' + window.location.port);
var audio = document.getElementById('audioSource');
console.log("hoi");
socket.on('start', function (data)
console.log("start");
console.log(data);
// socket.emit('my other event', my: 'data' );
socket.emit('stream', my: 'data' );
console.log("");
ss(socket).on('audio-stream', function(stream, data)
parts = ;
console.log("DATA -->> ")
stream.on('data', (chunk) =>
console.log(chunk);
parts.push(chunk);
);
stream.on('end', function () );
);
);
</script>
</body>
</html>





Here is my server.js file






var express = require('express');
var app = express();
var server = require('http').Server(app);
var fs = require('fs');
var io = require('socket.io')(server);
var ss = require('socket.io-stream');

app.use(express.static(`$__dirname/html`));

server.listen('5001');

app.get('/', function (req, res)
res.sendFile(__dirname + '/index2.html');
);


io.on('connection', function (socket)
socket.emit('start', hello: 'world' );
socket.on('stream', function (data)
console.log(data);
var stream = ss.createStream();
var filename = __dirname + '/audio/musicfile.mp3' ;
ss(socket).emit('audio-stream', stream, name: filename );
fs.createReadStream(filename).pipe(stream);
);
);





Also please suggest any pointers (latest tutorials/articles related to socket audio streaming).










share|improve this question



















  • 1




    Quick question do you have the file socket.io-stream.js located in your public directory so it is accessible at the url: localhost:5001/socket.io-stream/socket.io-stream.js ? does it work if you use "cdnjs.cloudflare.com/ajax/libs/socket.io-stream/0.9.1/…" instead?
    – Lagoni
    Nov 10 at 19:52










  • @Lagoni That worked(When using the cdnjs link.). Thanks. However, moving forward with the requirement, when I'm getting the mp3 file played in my windows machine when accessing the url: localhost:5001 , why am I not able to play the file in mobile connected to 192.168.x.x:5001/ when both are in same LAN. I can see the html file loaded with audio controls, but unable to hit the play button. Any suggestions?
    – beta programmers
    Nov 10 at 21:36







  • 1




    My guess is the var socket = io('http://localhost:' + window.location.port); it then tries to access the socket locally, on your phone. Which is not where your socket server is located :) I believe you can just say var socket = io(); since your socket server is located on the same port as your express server.
    – Lagoni
    Nov 10 at 21:47










  • Guess worked right. Now, able to get this working mobile as well. When I'm hitting the url in mobile, I was expecting the mp3 file to continue from a certain point of song length. I can use a method similar to audio.setPosition and then play, however, I'm trying a solution similar to icecast live streaming approach. Can we do this using sockets?
    – beta programmers
    Nov 10 at 21:59










  • Unfortunately i do not have any experience with either icecast or socket.io-stream, but i know that createReadStream have an option called start and end where you can specify where to read from and to. Hope that can guide you in the right direction :)
    – Lagoni
    Nov 10 at 22:05












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I was trying to create an mp3 stream (already added the .mp3 file in my machine) using socket.io-stream and access it using the client.html file.



After installing the socket.io-stream with npm and started, getting the below error in chrome console:




http://localhost:5001/socket.io-stream/socket.io-stream.js net::ERR_ABORTED 404 (Not Found)




and




Uncaught ReferenceError: ss is not defined




Here is my client.html file:






<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>bb</title>
</head>

<body>
<script src="/socket.io/socket.io.js"></script>
<script src="/socket.io-stream/socket.io-stream.js"></script>
<h1>Audio Testing 1 2 3</h1>
<audio id="audio" controls>
<source src="" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<br>


<script>
var socket = io('http://localhost:' + window.location.port);
var audio = document.getElementById('audioSource');
console.log("hoi");
socket.on('start', function (data)
console.log("start");
console.log(data);
// socket.emit('my other event', my: 'data' );
socket.emit('stream', my: 'data' );
console.log("");
ss(socket).on('audio-stream', function(stream, data)
parts = ;
console.log("DATA -->> ")
stream.on('data', (chunk) =>
console.log(chunk);
parts.push(chunk);
);
stream.on('end', function () );
);
);
</script>
</body>
</html>





Here is my server.js file






var express = require('express');
var app = express();
var server = require('http').Server(app);
var fs = require('fs');
var io = require('socket.io')(server);
var ss = require('socket.io-stream');

app.use(express.static(`$__dirname/html`));

server.listen('5001');

app.get('/', function (req, res)
res.sendFile(__dirname + '/index2.html');
);


io.on('connection', function (socket)
socket.emit('start', hello: 'world' );
socket.on('stream', function (data)
console.log(data);
var stream = ss.createStream();
var filename = __dirname + '/audio/musicfile.mp3' ;
ss(socket).emit('audio-stream', stream, name: filename );
fs.createReadStream(filename).pipe(stream);
);
);





Also please suggest any pointers (latest tutorials/articles related to socket audio streaming).










share|improve this question















I was trying to create an mp3 stream (already added the .mp3 file in my machine) using socket.io-stream and access it using the client.html file.



After installing the socket.io-stream with npm and started, getting the below error in chrome console:




http://localhost:5001/socket.io-stream/socket.io-stream.js net::ERR_ABORTED 404 (Not Found)




and




Uncaught ReferenceError: ss is not defined




Here is my client.html file:






<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>bb</title>
</head>

<body>
<script src="/socket.io/socket.io.js"></script>
<script src="/socket.io-stream/socket.io-stream.js"></script>
<h1>Audio Testing 1 2 3</h1>
<audio id="audio" controls>
<source src="" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<br>


<script>
var socket = io('http://localhost:' + window.location.port);
var audio = document.getElementById('audioSource');
console.log("hoi");
socket.on('start', function (data)
console.log("start");
console.log(data);
// socket.emit('my other event', my: 'data' );
socket.emit('stream', my: 'data' );
console.log("");
ss(socket).on('audio-stream', function(stream, data)
parts = ;
console.log("DATA -->> ")
stream.on('data', (chunk) =>
console.log(chunk);
parts.push(chunk);
);
stream.on('end', function () );
);
);
</script>
</body>
</html>





Here is my server.js file






var express = require('express');
var app = express();
var server = require('http').Server(app);
var fs = require('fs');
var io = require('socket.io')(server);
var ss = require('socket.io-stream');

app.use(express.static(`$__dirname/html`));

server.listen('5001');

app.get('/', function (req, res)
res.sendFile(__dirname + '/index2.html');
);


io.on('connection', function (socket)
socket.emit('start', hello: 'world' );
socket.on('stream', function (data)
console.log(data);
var stream = ss.createStream();
var filename = __dirname + '/audio/musicfile.mp3' ;
ss(socket).emit('audio-stream', stream, name: filename );
fs.createReadStream(filename).pipe(stream);
);
);





Also please suggest any pointers (latest tutorials/articles related to socket audio streaming).






<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>bb</title>
</head>

<body>
<script src="/socket.io/socket.io.js"></script>
<script src="/socket.io-stream/socket.io-stream.js"></script>
<h1>Audio Testing 1 2 3</h1>
<audio id="audio" controls>
<source src="" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<br>


<script>
var socket = io('http://localhost:' + window.location.port);
var audio = document.getElementById('audioSource');
console.log("hoi");
socket.on('start', function (data)
console.log("start");
console.log(data);
// socket.emit('my other event', my: 'data' );
socket.emit('stream', my: 'data' );
console.log("");
ss(socket).on('audio-stream', function(stream, data)
parts = ;
console.log("DATA -->> ")
stream.on('data', (chunk) =>
console.log(chunk);
parts.push(chunk);
);
stream.on('end', function () );
);
);
</script>
</body>
</html>





<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>bb</title>
</head>

<body>
<script src="/socket.io/socket.io.js"></script>
<script src="/socket.io-stream/socket.io-stream.js"></script>
<h1>Audio Testing 1 2 3</h1>
<audio id="audio" controls>
<source src="" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<br>


<script>
var socket = io('http://localhost:' + window.location.port);
var audio = document.getElementById('audioSource');
console.log("hoi");
socket.on('start', function (data)
console.log("start");
console.log(data);
// socket.emit('my other event', my: 'data' );
socket.emit('stream', my: 'data' );
console.log("");
ss(socket).on('audio-stream', function(stream, data)
parts = ;
console.log("DATA -->> ")
stream.on('data', (chunk) =>
console.log(chunk);
parts.push(chunk);
);
stream.on('end', function () );
);
);
</script>
</body>
</html>





var express = require('express');
var app = express();
var server = require('http').Server(app);
var fs = require('fs');
var io = require('socket.io')(server);
var ss = require('socket.io-stream');

app.use(express.static(`$__dirname/html`));

server.listen('5001');

app.get('/', function (req, res)
res.sendFile(__dirname + '/index2.html');
);


io.on('connection', function (socket)
socket.emit('start', hello: 'world' );
socket.on('stream', function (data)
console.log(data);
var stream = ss.createStream();
var filename = __dirname + '/audio/musicfile.mp3' ;
ss(socket).emit('audio-stream', stream, name: filename );
fs.createReadStream(filename).pipe(stream);
);
);





var express = require('express');
var app = express();
var server = require('http').Server(app);
var fs = require('fs');
var io = require('socket.io')(server);
var ss = require('socket.io-stream');

app.use(express.static(`$__dirname/html`));

server.listen('5001');

app.get('/', function (req, res)
res.sendFile(__dirname + '/index2.html');
);


io.on('connection', function (socket)
socket.emit('start', hello: 'world' );
socket.on('stream', function (data)
console.log(data);
var stream = ss.createStream();
var filename = __dirname + '/audio/musicfile.mp3' ;
ss(socket).emit('audio-stream', stream, name: filename );
fs.createReadStream(filename).pipe(stream);
);
);






javascript node.js sockets socket.io audio-streaming






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 20:15









James Z

11.1k71735




11.1k71735










asked Nov 10 at 19:38









beta programmers

248




248







  • 1




    Quick question do you have the file socket.io-stream.js located in your public directory so it is accessible at the url: localhost:5001/socket.io-stream/socket.io-stream.js ? does it work if you use "cdnjs.cloudflare.com/ajax/libs/socket.io-stream/0.9.1/…" instead?
    – Lagoni
    Nov 10 at 19:52










  • @Lagoni That worked(When using the cdnjs link.). Thanks. However, moving forward with the requirement, when I'm getting the mp3 file played in my windows machine when accessing the url: localhost:5001 , why am I not able to play the file in mobile connected to 192.168.x.x:5001/ when both are in same LAN. I can see the html file loaded with audio controls, but unable to hit the play button. Any suggestions?
    – beta programmers
    Nov 10 at 21:36







  • 1




    My guess is the var socket = io('http://localhost:' + window.location.port); it then tries to access the socket locally, on your phone. Which is not where your socket server is located :) I believe you can just say var socket = io(); since your socket server is located on the same port as your express server.
    – Lagoni
    Nov 10 at 21:47










  • Guess worked right. Now, able to get this working mobile as well. When I'm hitting the url in mobile, I was expecting the mp3 file to continue from a certain point of song length. I can use a method similar to audio.setPosition and then play, however, I'm trying a solution similar to icecast live streaming approach. Can we do this using sockets?
    – beta programmers
    Nov 10 at 21:59










  • Unfortunately i do not have any experience with either icecast or socket.io-stream, but i know that createReadStream have an option called start and end where you can specify where to read from and to. Hope that can guide you in the right direction :)
    – Lagoni
    Nov 10 at 22:05












  • 1




    Quick question do you have the file socket.io-stream.js located in your public directory so it is accessible at the url: localhost:5001/socket.io-stream/socket.io-stream.js ? does it work if you use "cdnjs.cloudflare.com/ajax/libs/socket.io-stream/0.9.1/…" instead?
    – Lagoni
    Nov 10 at 19:52










  • @Lagoni That worked(When using the cdnjs link.). Thanks. However, moving forward with the requirement, when I'm getting the mp3 file played in my windows machine when accessing the url: localhost:5001 , why am I not able to play the file in mobile connected to 192.168.x.x:5001/ when both are in same LAN. I can see the html file loaded with audio controls, but unable to hit the play button. Any suggestions?
    – beta programmers
    Nov 10 at 21:36







  • 1




    My guess is the var socket = io('http://localhost:' + window.location.port); it then tries to access the socket locally, on your phone. Which is not where your socket server is located :) I believe you can just say var socket = io(); since your socket server is located on the same port as your express server.
    – Lagoni
    Nov 10 at 21:47










  • Guess worked right. Now, able to get this working mobile as well. When I'm hitting the url in mobile, I was expecting the mp3 file to continue from a certain point of song length. I can use a method similar to audio.setPosition and then play, however, I'm trying a solution similar to icecast live streaming approach. Can we do this using sockets?
    – beta programmers
    Nov 10 at 21:59










  • Unfortunately i do not have any experience with either icecast or socket.io-stream, but i know that createReadStream have an option called start and end where you can specify where to read from and to. Hope that can guide you in the right direction :)
    – Lagoni
    Nov 10 at 22:05







1




1




Quick question do you have the file socket.io-stream.js located in your public directory so it is accessible at the url: localhost:5001/socket.io-stream/socket.io-stream.js ? does it work if you use "cdnjs.cloudflare.com/ajax/libs/socket.io-stream/0.9.1/…" instead?
– Lagoni
Nov 10 at 19:52




Quick question do you have the file socket.io-stream.js located in your public directory so it is accessible at the url: localhost:5001/socket.io-stream/socket.io-stream.js ? does it work if you use "cdnjs.cloudflare.com/ajax/libs/socket.io-stream/0.9.1/…" instead?
– Lagoni
Nov 10 at 19:52












@Lagoni That worked(When using the cdnjs link.). Thanks. However, moving forward with the requirement, when I'm getting the mp3 file played in my windows machine when accessing the url: localhost:5001 , why am I not able to play the file in mobile connected to 192.168.x.x:5001/ when both are in same LAN. I can see the html file loaded with audio controls, but unable to hit the play button. Any suggestions?
– beta programmers
Nov 10 at 21:36





@Lagoni That worked(When using the cdnjs link.). Thanks. However, moving forward with the requirement, when I'm getting the mp3 file played in my windows machine when accessing the url: localhost:5001 , why am I not able to play the file in mobile connected to 192.168.x.x:5001/ when both are in same LAN. I can see the html file loaded with audio controls, but unable to hit the play button. Any suggestions?
– beta programmers
Nov 10 at 21:36





1




1




My guess is the var socket = io('http://localhost:' + window.location.port); it then tries to access the socket locally, on your phone. Which is not where your socket server is located :) I believe you can just say var socket = io(); since your socket server is located on the same port as your express server.
– Lagoni
Nov 10 at 21:47




My guess is the var socket = io('http://localhost:' + window.location.port); it then tries to access the socket locally, on your phone. Which is not where your socket server is located :) I believe you can just say var socket = io(); since your socket server is located on the same port as your express server.
– Lagoni
Nov 10 at 21:47












Guess worked right. Now, able to get this working mobile as well. When I'm hitting the url in mobile, I was expecting the mp3 file to continue from a certain point of song length. I can use a method similar to audio.setPosition and then play, however, I'm trying a solution similar to icecast live streaming approach. Can we do this using sockets?
– beta programmers
Nov 10 at 21:59




Guess worked right. Now, able to get this working mobile as well. When I'm hitting the url in mobile, I was expecting the mp3 file to continue from a certain point of song length. I can use a method similar to audio.setPosition and then play, however, I'm trying a solution similar to icecast live streaming approach. Can we do this using sockets?
– beta programmers
Nov 10 at 21:59












Unfortunately i do not have any experience with either icecast or socket.io-stream, but i know that createReadStream have an option called start and end where you can specify where to read from and to. Hope that can guide you in the right direction :)
– Lagoni
Nov 10 at 22:05




Unfortunately i do not have any experience with either icecast or socket.io-stream, but i know that createReadStream have an option called start and end where you can specify where to read from and to. Hope that can guide you in the right direction :)
– Lagoni
Nov 10 at 22:05

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242721%2fsocket-io-stream-facing-404-issue-when-accessing-in-socket-client-and-server-als%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242721%2fsocket-io-stream-facing-404-issue-when-accessing-in-socket-client-and-server-als%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto