Timeout connection Electron > Socket.io (namespace.use)


#1

On the server when i set “io.use”, the client(Electron) have a timeout for saying he is connected to the server. Why the client(Electron) can’t connect immediately on the server?

the server:

let server = require('http').createServer();
let io = require('socket.io')(server);

io.use((socket, next) => {
  if (true) return next();
  next(new Error('Authentication error'));
});

io.on('connection', function (socket) {
    console.log('connected !');
});

server.listen(3002)

the client:

const electron = require(‘electron’)
const app = electron.app
const BrowserWindow = electron.BrowserWindow

const path = require(‘path’)
const url = require(‘url’)
const io = require(“socket.io-client”)

let mainWindow

function createWindow () {
mainWindow = new BrowserWindow({width: 800, height: 600})

mainWindow.loadURL(url.format({
pathname: path.join(__dirname, ‘index.html’),
protocol: ‘file:’,
slashes: true
}))

mainWindow.on(‘closed’, function () {
mainWindow = null
})

let socket = io.connect(‘http://localhost:3002’)

socket.on(‘connect’, () => {
console.log(“connected”)
})
}

app.on(‘ready’, createWindow)

app.on(‘window-all-closed’, function () {
if (process.platform !== ‘darwin’) {
app.quit()
}
})

app.on(‘activate’, function () {
if (mainWindow === null) {
createWindow()
}
})

socket.io-client: “2.0.3”
electronjs: “1.4.1”


#2

I can’t help with this, but in order for you to find someone who can, you should post your code formatted so that the forum knows it’s code, either by fencing it in accordance with the GitHub-Flavored Markdown rules, or by highlighting it and pressing the </> button above the editor.