Couldn't get any response from the web socket server












0















I have created a socket connection and i want to test that connection in web socket server but I couldn't get any response from the server.



I made a web socket app which provides the details on input from the client and I want to implement the same on web socket server but it didn't work.



Index.js file



 var express = require('express');
var socket = require('socket.io');
var fs = require("fs");

var app = express();




var server = app.listen(3000);
app.use(express.static('public'));


var io = socket(server);
io.on('connection', (socket) => {

socket.on('chat', function(data){

let res = data.split(",");
for(let i = 0; i<res.length;i++)
{
res[i] = res[i].slice(1,12);
fs.readFile('data.json', (err, data) =>
{
if (err) throw err;
let client = JSON.parse(data);
console.log(client[res[i]]);


io.to(socket.id).emit('chat', client[res[i]]);
socket.broadcast.emit('chat', client[res[i]]);
});
}

});

});


chat.js file
var socket = io.connect('http://localhost:3000');



  var message = document.getElementById('message'),
btn = document.getElementById('send'),


btn.addEventListener('click', function(){

socket.emit('chat', message.value);
});


socket.on('chat', function(data)

{
console.log(data);
}


It works fine when I run the port http://localhost:3000/
but when I test it on ws://localhost:3000/socket.io/?EIO=3&transport=websocket
then i didn't get any response.










share|improve this question























  • That's because socket.io isn't a WebSocket implementation.

    – robertklep
    Jan 1 at 9:43
















0















I have created a socket connection and i want to test that connection in web socket server but I couldn't get any response from the server.



I made a web socket app which provides the details on input from the client and I want to implement the same on web socket server but it didn't work.



Index.js file



 var express = require('express');
var socket = require('socket.io');
var fs = require("fs");

var app = express();




var server = app.listen(3000);
app.use(express.static('public'));


var io = socket(server);
io.on('connection', (socket) => {

socket.on('chat', function(data){

let res = data.split(",");
for(let i = 0; i<res.length;i++)
{
res[i] = res[i].slice(1,12);
fs.readFile('data.json', (err, data) =>
{
if (err) throw err;
let client = JSON.parse(data);
console.log(client[res[i]]);


io.to(socket.id).emit('chat', client[res[i]]);
socket.broadcast.emit('chat', client[res[i]]);
});
}

});

});


chat.js file
var socket = io.connect('http://localhost:3000');



  var message = document.getElementById('message'),
btn = document.getElementById('send'),


btn.addEventListener('click', function(){

socket.emit('chat', message.value);
});


socket.on('chat', function(data)

{
console.log(data);
}


It works fine when I run the port http://localhost:3000/
but when I test it on ws://localhost:3000/socket.io/?EIO=3&transport=websocket
then i didn't get any response.










share|improve this question























  • That's because socket.io isn't a WebSocket implementation.

    – robertklep
    Jan 1 at 9:43














0












0








0








I have created a socket connection and i want to test that connection in web socket server but I couldn't get any response from the server.



I made a web socket app which provides the details on input from the client and I want to implement the same on web socket server but it didn't work.



Index.js file



 var express = require('express');
var socket = require('socket.io');
var fs = require("fs");

var app = express();




var server = app.listen(3000);
app.use(express.static('public'));


var io = socket(server);
io.on('connection', (socket) => {

socket.on('chat', function(data){

let res = data.split(",");
for(let i = 0; i<res.length;i++)
{
res[i] = res[i].slice(1,12);
fs.readFile('data.json', (err, data) =>
{
if (err) throw err;
let client = JSON.parse(data);
console.log(client[res[i]]);


io.to(socket.id).emit('chat', client[res[i]]);
socket.broadcast.emit('chat', client[res[i]]);
});
}

});

});


chat.js file
var socket = io.connect('http://localhost:3000');



  var message = document.getElementById('message'),
btn = document.getElementById('send'),


btn.addEventListener('click', function(){

socket.emit('chat', message.value);
});


socket.on('chat', function(data)

{
console.log(data);
}


It works fine when I run the port http://localhost:3000/
but when I test it on ws://localhost:3000/socket.io/?EIO=3&transport=websocket
then i didn't get any response.










share|improve this question














I have created a socket connection and i want to test that connection in web socket server but I couldn't get any response from the server.



I made a web socket app which provides the details on input from the client and I want to implement the same on web socket server but it didn't work.



Index.js file



 var express = require('express');
var socket = require('socket.io');
var fs = require("fs");

var app = express();




var server = app.listen(3000);
app.use(express.static('public'));


var io = socket(server);
io.on('connection', (socket) => {

socket.on('chat', function(data){

let res = data.split(",");
for(let i = 0; i<res.length;i++)
{
res[i] = res[i].slice(1,12);
fs.readFile('data.json', (err, data) =>
{
if (err) throw err;
let client = JSON.parse(data);
console.log(client[res[i]]);


io.to(socket.id).emit('chat', client[res[i]]);
socket.broadcast.emit('chat', client[res[i]]);
});
}

});

});


chat.js file
var socket = io.connect('http://localhost:3000');



  var message = document.getElementById('message'),
btn = document.getElementById('send'),


btn.addEventListener('click', function(){

socket.emit('chat', message.value);
});


socket.on('chat', function(data)

{
console.log(data);
}


It works fine when I run the port http://localhost:3000/
but when I test it on ws://localhost:3000/socket.io/?EIO=3&transport=websocket
then i didn't get any response.







node.js websocket socket.io






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 7:08









Ayush SinghAyush Singh

32




32













  • That's because socket.io isn't a WebSocket implementation.

    – robertklep
    Jan 1 at 9:43



















  • That's because socket.io isn't a WebSocket implementation.

    – robertklep
    Jan 1 at 9:43

















That's because socket.io isn't a WebSocket implementation.

– robertklep
Jan 1 at 9:43





That's because socket.io isn't a WebSocket implementation.

– robertklep
Jan 1 at 9:43












0






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',
autoActivateHeartbeat: false,
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%2f53993679%2fcouldnt-get-any-response-from-the-web-socket-server%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993679%2fcouldnt-get-any-response-from-the-web-socket-server%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







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas