1

I have ShoutBox in my site. It’s implement in websocket on client site, and php in back-end. I decided to rewrite back-end in node.js as part of study. I write server in PHP so it should be easy.

So I start on find something done already, available library on this site: https://github.com/joyent/node/wiki/Modules#wiki-ws-ajax

Socket.io -> after install, when I see code and files which is necessary to work I think c’mon. Okay a lot of features (e.g: websocket,flash socket, AJAX long polling), but what for ? If someone want use websocket they want websocket, if your browser not support it, download the latest version. I can write the same about support protocol (hixie…hybid -> RFC 6455 is enough since dec 2011, 1 year ), now all browser support RCF. People who have oldest version browser, will need update they browser anyway. So it’s a lot of unnecessary code.

This is just my thoughts, you can’t agree with that, I don’t have a lot of developer experience in big company. Finally I decided to find something slighter. I just want support RCF 6455.

Ws -> support 3 protocol, okay I can accept this. I start analyze code, I give up after 5 min. I starts have doubt for my JavaScript knowledge.

I check something about 6 -7 library, each is based on websocket.io or have some weird code. This same situation I have when I look for PHP websocket server. My code have 161 line, I’m pretty sure this same result in node.js, after deleted all unnecessary stuff like protocol. Only solution is to write my own server.

Okay go to node.js docs and where I should start? Totally confused. Use http or net module? Previous library use http, but in net module is socket class, the name suggest I need it.

I have net.connect(options, [connectionListener]) and net.connect(port, [host], [connectListener]). Why? It isn't the same ?

I've looked for example code, it’s good place to find out. It isn’t there, only example is library. So I have big request, someone who has its own very simple websocket server can share it with me , please ? connect, handshake, broadcast msg to all connected (msg massage lower than < 65535)

EDIT: Give up at all, is impossible for me, until someone make DOCs readable.

I forget write that in some module you also need include file in client site. What for? Can you tell me why someone write client when is already there ? http://www.w3.org/TR/websockets/

On that list I pasted, everyone can get ? I found there module which don’t work at all. Or what doing there module which is based on socket.io, it is the same. Why even someone write they?

I can’t understand why somebody need add some c++ code when other don’t need them in this same case?

halfer
  • 19,824
  • 17
  • 99
  • 186
Sonny D
  • 897
  • 9
  • 29
  • 2
    you gave up socket.io because it has many features ? you obviously don't need them all, just one or two of them.. you shouldn't analyze the whole library just to understand and implement something, documentations always will provide information about anything in library and how to use .. seriously just reconsider socket.io , take a look at the examples .. and don't reinvent the wheel – Gntem Jun 27 '13 at 08:29
  • I don't want reinvent the wheel :D I just want server which I understand. – Sonny D Jun 27 '13 at 13:46
  • **socket.io** is goddam easy, so just read [how to use it](http://socket.io/#how-to-use). If you're going to work with open source projects, learn how to reuse what the community did. And it did a lot. – eepp Jun 27 '13 at 15:01

1 Answers1

0

I too have a small nit-picking issue with the ws module. They do not delete the socket object data after closing and it becomes a nuisance because all of data is then pushed into memory and it becomes a memory leak UNTIL the V8 Garbage Collector deletes the unused data. It's fine in 1 sense, but if you have a gameserver, or a VERY active game where people are refreshing/joining channels/games/etc, that extra overhead adds quite a bit of unnecessary memory usage. I believe the ws module would work best if they could delete the temporary socket object properties upon closing instead of waiting for the V8 GC to.

With that said, it's a minimal amount of data and the average user won't even notice it unless they have a very active server.

In any event, take a look at this gem that I found last night: https://www.npmjs.com/package/lark-websocket

Very bare-bones system of supporting text web-sockets with a very, very simple api. The only issue is, the author does not use try / catch blocks within the code so I'm sure you don't want to use it on a production server. The overhead is extremely small compared to the ws module and in my gameserver testing within nodejs it works beautifully.

However, the ws module and lark-websocket are both equally simple to use.. I'm just thinking you'll like this one better as it seems more 'lightweight', hope this helps.

Community
  • 1
  • 1
NiCk Newman
  • 1,716
  • 7
  • 23
  • 48