1

For socket.io, how do you listen to incoming data other than those emitted as "event" types? I am looking to read and detect the ProxyProtocol string.

ngzhongcai
  • 1,793
  • 3
  • 23
  • 31
  • What do you mean `ProxyProtocol` string? An already established socket.io socket only sends one kind of datagram. Establishing a socket.io connection starts with an http request because that's how a webSocket works – jfriend00 Apr 23 '15 at 04:08
  • My socket.io server sits behind a LoadBalancer that sends sends a ProxyProtocol string whose structure is like "PROXY TCP4 198.51.100.22 203.0.113.7 35646 80\r\n". It's not wrapped in any HTTP, just a string. Not sure if it's possible. – ngzhongcai Apr 23 '15 at 04:17
  • 1
    Sends that string how? It can't be sending that on the webSocket as that would be a protocol violation. – jfriend00 Apr 23 '15 at 04:21
  • 1
    Do you not even get HIHIHI on a regular browser https request to the server (not a websocket request)? Are you sure your https server is listening? – jfriend00 Apr 23 '15 at 05:10

1 Answers1

1

I did a little research. It looks like the proxy string is sent with the initial http request on a separate line from the GET command like this:

PROXY TCP4 192.168.0.1 192.168.0.11 56324 80\r\n
GET / HTTP/1.1\r\n
Host: 192.168.0.11\r\n
\r\n  

You can see this explained in this article.

So, that would need to be handled by the http server that fields the initial HTTP request that starts the webSocket. This occurs in the initial connection stage before the webSocket is established. So, it is not something you listen to afterwards. It would take some study of socket.io code to figure out if it already stores that information on a socket.io socket or how you could hook into the initial http handler to see this info. I will do a little more research.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • Wow, thanks buddy! Your answer did give me some ideas. I'm now figuring out how to get it from the NodeJS HTTP layer – ngzhongcai Apr 23 '15 at 04:45
  • Hi jfriend00, I tried to get it from the HTTP layer. But it's not working. Can you see the above EDIT? – ngzhongcai Apr 23 '15 at 05:05
  • @ngzhongcai - check out [this answer](http://stackoverflow.com/questions/11182980/not-getting-remote-address-while-using-proxy-in-socket-io) which suggests you can get the remoteAddress from `socket.handshake.headers['x-forwarded-for'] || socket.handshake.address.address` where `socket` is the socket.io socket. – jfriend00 Apr 23 '15 at 05:25
  • Hi jfriend00, it's a little more tacky. AWS ELB. ProxyProtocol. Socket.Io. – ngzhongcai Apr 23 '15 at 11:11