By sheshant
when i connect client side to server side over cross origin, Client side start sending multiple connection request every time. My client side code:-
var socket; $(document).ready(function(){
var n="hello";
socket = io("ws://ip_address:4000",{query:'name='+n});
socket.on('connect', function() {
if(socket.connected==true) {
$("body").fadeIn('slow');
}
});
socket.on('disconnect', function() {
if(socket.disconnected==true) {
$("body").fadeOut('slow'); }
});
Server Side
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var date = require('date-and-time');
var mysql = require('mysql');
var pool =mysql.createPool({
connectionLimit : 100, //important
host : 'localhost',
user : 'root',
password : 'my_pass'
database : 'db',
debug : false
});
io.on('connection', function(socket){
var store =socket.handshake.query.name;
console.log(store);
console.log(socket.id);
});
And the console.log result in SSH is
sheshant@nodejs-1gb-blr1-01:~/chatmachine$ node index.js
listening on *:4000
sheshantsinha@gmail.com
YwbTs36JwRQ_SNxPAAAA
sheshantsinha@gmail.com
jsrVBh4fvKdicCX4AAAB
sheshantsinha@gmail.com
WJ3hdI2vftyyey5LAAAC
sheshantsinha@gmail.com
5fhlkkxkf9VWHUDnAAAD
sheshantsinha@gmail.com
VC-0GfN6L_QvnOVVAAAE
sheshantsinha@gmail.com
JF7cxxbItBTq_x4JAAAF
sheshantsinha@gmail.com
BdvIAHCCkqox91mVAAAG
sheshantsinha@gmail.com
h2iZ5IgQMnNWg3rKAAAH
sheshantsinha@gmail.com
7KVUL7u2ZlFWgsn_AAAI
sheshantsinha@gmail.com
rlPWNyQI0xFnwxhEAAAJ
sheshantsinha@gmail.com
ihAPsPCuQEPKiinSAAAK
sheshantsinha@gmail.com
FMf4hV3qKmilkocNAAAL
sheshantsinha@gmail.com
6shVbfFMMzCy2SmRAAAM
sheshantsinha@gmail.com
fwWlKt52V2WNgvgoAAAN
sheshantsinha@gmail.com
-iELmL8muGMZfT8SAAAO
sheshantsinha@gmail.com
But i am expecting only one connection request per user
sheshant@nodejs-1gb-blr1-01:~/chatmachine$ node index.js
listening on *:4000
fwWlKt52V2WNgvgoAAAN
sheshantsinha@gmail.com
When i do Inspect element and open network, There i see that, It send below request many time even after connection.
http://MY_IP_ADDRESS:PORT/socket.io/?name=sheshantsinha%40gmail.com&EIO=2&transport=polling&t=1497514896811-26
Request Method:GET
Status Code:200 OK
How one can resolve this problem
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
I solve it by using the latest version in the client and server it happened because I used the latest version in the frontend and the old version in the backend
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.