2

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

Wazy
  • 8,822
  • 10
  • 53
  • 98
  • 1
    Do you mean you want raw data exchange rather than HTTP formatted communication? – JScoobyCed Dec 04 '12 at 05:56
  • I know HTTP is a layer built on top of the TCP layer, but what i want is pure TCP connection for better performance in heavy traffic... – Wazy Dec 04 '12 at 05:57

1 Answers1

2

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.

Community
  • 1
  • 1
JScoobyCed
  • 10,203
  • 6
  • 34
  • 58
  • 1
    Thanks I know it, but what i want is pure TCP connection for better performance in heavy traffic... – Wazy Dec 04 '12 at 05:55
  • I don't think you can do that with Socket.io. You'll have to use native sockets, and those can't interact directly with a browser. – Nelson Dec 04 '12 at 06:05
  • But `socket.io` has a method `net.createServer()`.Is their any way to use `socket.io` to connect to this TCP server – Wazy Dec 04 '12 at 07:01
  • You might have found it out already, but once the HTTP hand-shake protocol is done, the connection is almost sending raw data. Only 2 frame bytes are used as extra data, the rest is all your data, reaching the minimum overhead you are looking for. – JScoobyCed Jan 22 '13 at 02:09