18

I'm trying to run socket.io and I'm getting a bunch of these:

http://domain.com:8080/socket.io/?EIO=2&transport=polling&t=1401421022966-0 400 (Bad Request) 

This is the response I'm getting:

{"code":0,"message":"Transport unknown"}

I can't find any reason. I read somewhere that it might be misinterpreting the client, but that's about as far as I could get.

JVE999
  • 3,327
  • 10
  • 54
  • 89
  • 1
    It seems like your url is not well formed. Does taking out the slash after socket.io improve your situation? Sooo, it would look like `http://domain.com:8080/socket.io?EIO=2&transport=polling&t=1401421022966-0` – grobot May 30 '14 at 03:59
  • 1
    From socket.io's doc, here are socket.io default transports: websocket, htmlfile, xhr-polling, jsonp-polling – Ben May 30 '14 at 04:29
  • @grobot There is nothing malformed about that URL. Slashes are quite common in URL's, even at the end. – Brandon Jan 03 '15 at 02:57

7 Answers7

19

I had the same issue after upgrading from 0.9.x to 1.x.x. Shortening the long story, I would set transports to ['websocket', 'polling'] and then the error...

when you config your server to use specefic transpors you should set the same config on client side to...

server

    var io = require('socket.io')(server, {'transports': ['websocket', 'polling']});

client

    var io = io( serverUri, {'transports': ['websocket', 'polling']});
smbeiragh
  • 691
  • 7
  • 6
  • 2
    Where are these files? – Csaba Toth Feb 13 '15 at 18:02
  • i know this is late, in 2021, but let me thank you. I looked everywhere, and everybody was always solving problems by having matching versions of client and server which I already had. In my case, as soon as i blocked the transport to websocket on the server, i got the bad request error, because client was still trying to use polling! declaring transport on client as well did it! Thanks again! – MaX May 11 '21 at 10:52
16

I had the same issue,after upgrading from 0.9.x, turns out my server config was set to ['websocket', 'jsonp-polling'] which was valid in 0.9 but the default config for the client and server is now ['polling', 'websocket']. Removing my server config got me up and running.

The config is now documented in engine.io (https://github.com/automattic/engine.io), the new transport layer introduced in 1.0 - in particular this line:
transports ( String): transports to allow connections to (['polling', 'websocket'])

johnl
  • 161
  • 2
  • 2
    Can you enlighten me on where the server config is? I just completely uninstalled the socket.io folder in node_modules and reinstalled and I'm still getting this problem. – River Tam Jul 11 '14 at 03:46
  • This fixed it! Fantastic. @RiverTam The config would be in your code somewhere. – Brad Dec 03 '14 at 02:54
  • 1
    Where is this config file? – Csaba Toth Feb 13 '15 at 18:02
  • http://prntscr.com/g3ekl8 chat is working fine but the newrelic logs this.I also found all logs are from Windows NT 6.1 which may be try to connect using polling any suggestion – Max Aug 02 '17 at 12:06
3

i had the same issue:

Getting the latest socket-client.js and using these file on clientside, solved this problem for me.

turtec
  • 51
  • 2
  • Using the latest client javascript file fixed this problem for me too: https://cdn.socket.io/socket.io-1.3.5.js – Dave Sep 02 '15 at 04:27
2

This happened to me when I served the socket.io.js script myself. I had to go copy node_modules/socket.io/node_modules/socket.io-client/socket.io.js to where I was serving it up.

Drew LeSueur
  • 19,185
  • 29
  • 89
  • 106
  • Could you elaborate on that? – Csaba Toth Feb 13 '15 at 18:01
  • This was a while ago, but if I remember right If my page loads on foo.com, but I am connecting to a websocket on bar.com, I had to copy the socket.io.js file onto foo.com and load it from there. I don't know if that solution will still work, or if it's the best way to do it. – Drew LeSueur Feb 13 '15 at 18:34
  • Solved my problem! I used an old version in which I loaded a local version instead of directly from the node instance – Jos Mar 25 '15 at 16:32
1

Try this configuration on server side:

const io = require('socket.io')(server, {
    cors: {
        origin: "http://localhost:8100",
        methods: ["GET", "POST"],
        credentials: true
    },
    transports: ['websocket', 'polling'],
    allowEIO3: true
});
Elikill58
  • 4,050
  • 24
  • 23
  • 45
Rohit M
  • 451
  • 4
  • 8
0

My solution was to upgrade node.js to latest (0.12.0 at the time of this post). Originally node.js was installed as a part of a bundle. Once I uninstalled that node.js coming from that bundle (Aptana 3 bundle, node.js was somewhat behind), and installed the latest from node.js's website, things started working finally.

I was experimenting with React.js. I spent several hours debugging the phenomena, I've found build errors in socket.io, specifically about socket.io-client, it tried to invoke Visual Studio MSBuild unsuccesfully. Which is sad, the error occured with node-gyp too. Apparently socket.io-client is not needed to run/serve my examples, and seems like these unfortunate errors (which lured me into an endless forest) can be ignored.

(I noticed also a module while installing webpack-dev-server, which is Darwin only (a.k.a. Mac OS X). That's fortunately an optional dependency. It's frightening though: I know that Apple is very hipster, but the majority of the world is non Mac.)

Csaba Toth
  • 10,021
  • 5
  • 75
  • 121
0

I fixed it acting in my server.js

the io instance is initialized as follow:

const io = socket.listen(httpServer, { serveClient: true })

Before I had { serveClient: false }, because otherwise, I was getting an error. But actually, if you want that your client takes io from the node instance you have to serve it.

UPDATE: At the end.. you want to simply have const io = socket.listen(httpServer) In this way is going to be true by default.