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).
javascript node.js sockets socket.io audio-streaming
add a comment |
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).
javascript node.js sockets socket.io audio-streaming
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 thevar 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 sayvar 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 calledstart
andend
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
add a comment |
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).
javascript node.js sockets socket.io audio-streaming
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
javascript node.js sockets socket.io audio-streaming
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 thevar 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 sayvar 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 calledstart
andend
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
add a comment |
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 thevar 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 sayvar 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 calledstart
andend
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 sayvar 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
andend
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