I receive this error when I'm trying to connect to the websocket
WebSocket connection to 'wss://ropsten.infura.io/ws' failed: Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received
Code snippet
import web3 from 'web3';
var web3lib = new web3(
new web3.providers.WebsocketProvider('wss://ropsten.infura.io/ws'),
);
console.log(
'provider in web3 eth: ' + JSON.stringify(web3lib.currentProvider),
);
console.log('New block in web3 eth: ' + web3lib.blockNumber);
var subscription = web3lib.eth.subscribe('newBlockHeaders', function(
error,
result,
) {
if (!error)
console.log("output of web3 stream"+JSON.stringify(result));
else
console.log('Error of web3 stream ' + JSON.stringify(result));
});
What am I doing wrong here?