Where is Socket.IO Client Library At?

, ,

decidedly frustrated with socket.io.js.

let me detail the issues.

first, there's no clear indication what it's supposed to be. Sure, it's clear it's a lib on top of WebSocket protocol, with added feature that if browser doesn't support WebSocket, it'll automatically use other means (aka transports) such going thru Flash, XMLHttpRequest, hidden iframe, etc.

but, Does it require Node.js? There's a server and client part. How are they related?

the home page is extremely simple, but those simple examples hide a confuse ball. Nowhere it tells you its relation to Node.js, or how server/client are related, or independent. And its FAQ, or its github pages, don't say neither. (instead, it has one hundred other links, none of which answers)

Answer: socket.io is 2 JavaScript libs, socket server and socket client. But also, it is a protocol, on top of WebSocket. So, other langs can implement it too without using Node.js or JavaScript.

Answer: socket.io has socket server lib and socket client lib parts, and can be used independently. The socket server lib depends on Node.js (obviously), but the socket client lib do not necessarily need Node.js, but can use Node.js. That is, If your web server that uses the socket client is also running on Node.js. (for example, you have 2 servers, A and B. A is running Node and is the socket server. B is running Apache on another domain name and needs to talk to server A. So, B is your socket client, and you can use socket.io.js the client lib part. But if A and B are the same domain/server, then things are simpler. The socket client can load the same file the socket server is using (thus is using Node.js).)

Now, the first thing to do is actually to get it. The doc says: npm install socket.io -g. That gets you ≈600 files.

you see, all i need now is a socket client. As with most js lib, typically it's just a minimized file. How do i know which of the 600 files is it? Note that these 600 files includes README, build files, and also includes other libs such as Redis database interface, etc. It's essentially the same as from git. Hello?? why would i need npm install if i can just git clone the source code? npm is suppose to be a package manager, not giving me the source code junks.

the home page shows real beautiful simple examples, such as:

<script src="/socket.io/socket.io.js"></script>
<script>
  var socket = io.connect('http://localhost');
  socket.on('news', function (data) {
    console.log(data);
    socket.emit('my other event', { my: 'data' });
  });
</script>

but there's no such dir as “socket.io”? If you do a simple Google Search “Where is the socket.io client library?” You find several hits on StackOverflow. Clearly, lots people are confused. SO's answers isn't very good neither.

Answer: again, there are 2 libs, one for socket server and one for socket client, and can be used independently.

For socket server part, you need Node.js, of course. And, the file is: 〔/node_modules/socket.io/lib/socket.io.js〕

for the socket client part, if it is running on the same server as the socket server, you an also load that same file, because that file will somehow find the client.

but, if your socket client is not using Node.js, then, the client file you need to load is this:

<script src="http://example.com/node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.min.js"></script>

just exactly which of the 600 files are the minimally required for server and or client? i haven't found out yet.

at this point, i'm dithering whether to ditch socket.io, and just use WebSocket in plain old JavaScript.

sometimes i wonder, why software industry is such a hell? the guy who wrote socket.io.js, clearly is a smart guy, and expert at js and Node.js. And, his lib API is quite simple. Just a handful of functions. As his examples on his home page shows. And, i've seen his writings. Typically, programers don't know how to write, such as unix man page idiots or python idiots or perl. But, this guy knows how to write well.

So, why is such a simple API socket.io home page have so confusing doc?

is it not clear, first thing people need to do is load the file? and you didn't specify which file?

also, no where on the home page says: Documentation or Manual. You have to grok, and eventually something like a API doc is in the description page of the github page.

no where says that the client/server libs are separate projects. (yes, the client part actually has its own github repo. The server lib seems to include the client repo in its repo.)

is it not clear, when people follow your npm install socket.io example, they get 600 files, and none has the dir you showed in your simple examples on your home page?

i'm a beginner of Node.js. If something is incorrect, or if you know some answer, please comment. Thanks.

blog comments powered by Disqus