Determining whether socket.io TCP or HTTP

2019-07-14 06:38发布

问题:

This is my node server

var io = require('socket.io').listen(8889);
io.sockets.on('connection', function (socket) {
    socket.emit('news', { hello: 'world' });
    socket.on('my other event', function (data) {
        console.log(data);
    });
});

I am trying to connect to this node server from client side with the help of socket.io.js

I dont have any problem with the connection
My requirement is that I want to create a TCP connection to which clients can connect
But how can I know and confirm the server is a TCP type or HTTP type

回答1:

Socket.IO is a Lightweight protocol that sits on top of HTTP.

https://github.com/LearnBoost/socket.io-spec

You can see more info there https://stackoverflow.com/a/8053026/1012381 But in short you can't have raw data connection by the browser.