question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can socket.io-client use https?

See original GitHub issue

Can socket.io-client use https?

connect does not run.

Is option missing?

//設定ファイルの読み込み
require('dotenv').config();

var fs = require('fs');
var ssl_server_key = '../../ssl/new_server.key';
var ssl_server_crt = '../../ssl/server.crt';
var options = {
    key: fs.readFileSync(ssl_server_key),
    cert: fs.readFileSync(ssl_server_crt),
    pfx: fs.readFileSync(ssl_server_crt),
    passphrase: process.env.HTTPS_PASS
};

//socket.io-clientでサーバへ接続
var client = require('socket.io-client');
var socket = client.connect('https://localhost:30000/namespace',options);

//処理
//connectしたら'how are you?'とメッセージを送信する
socket.on('connect',function(){
    console.log('yea!!');
    socket.send('how are you?');
    socket.disconnect();
    process.exit(0);
});

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

19reactions
ikuratakashicommented, Oct 8, 2018

This is important.

options = { secure:true, reconnect: true, rejectUnauthorized : false };

Thank you.

1reaction
darrachequesnecommented, Jan 28, 2021

Example added here: https://socket.io/docs/v3/client-initialization/#Node-js-specific-options

Client

const fs = require("fs");
const socket = require("socket.io-client")("https://example.com", {
  ca: fs.readFileSync("./cert.pem")
});

Server

const fs = require("fs");
const server = require("https").createServer({
  cert: fs.readFileSync("./cert.pem"),
  key: fs.readFileSync("./key.pem")
});
const io = require("socket.io")(server);
Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js, socket.io with SSL - Stack Overflow
Use a secure URL for your initial connection, i.e. instead of "http://" use "https://". If the WebSocket transport is chosen, then Socket.
Read more >
Server Initialization | Socket.IO
Once you have installed the Socket.IO server library, you can now init the server. The complete list of options can be found here....
Read more >
Create a Secure Chat Application with Socket.IO and React
This tutorial shows you how to create a real-time chat application using JavaScript and Socket.IO.
Read more >
socket.io-client - npm
Start using socket.io-client in your project by running `npm i socket.io-client`. ... The source code of the website can be found here.
Read more >
Encrypted Websockets with Express and Socket.io
Everything must be encrypted over an HTTPS webpage, including Websocket connections. Major browsers like Safari block insecure Websocket connections on ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found