He didn't post source code (as far as I could tell, after searching for two minutes :) but I was able to cobble something together yesterday along the same lines.
Here's the client:
and server:
This works with Guille's node.websocket.js library. Start with that, then add chat.js into ./modules.
One last tweak is you have to add onDisconnect to node.websocket.js. I did that by adding the following:
if (this.module.onConnect) {
this.module.onConnect(this);
}
to the end of Connection.prototype._handshake. I suppose it could be called from elsewhere but that seems to work.
Check out amix's blog - lots of interesting details about how Plurk scales out to over 100,000 open connections. Hint: you don't do it with one thread per connection. The Servlet/CGI model is starting to look pretty old and creaky these days.
Update: bru has a node.websocket.js fork that includes a comet chat app. It's more complete than what I've posted here and he appears to have worked around the missing onConnect by just adding new connection objects in the onData callback.
WebSocket's simplicity on both the client and server side is what attracted me to it a few weeks ago.
ReplyDeleteSince then I've launched an actual site that uses WebSocket.
Since only the latest bleeding edge chrome builds natively support WebSocket, I used the truly great flash emulated version from here: http://github.com/gimite/web-socket-js
Since launching I've had a lot of people complain about it not working. I always followed it up with "Do you have flash?" and they always replied with No, or they had it blocked or had a really old version.
This convinced me that flash alone is not enough emulation to cover all the users.
So I've been working on WebSocket emulation using a comet server. At first I tried using Orbited, but it had issues running cross-domain in certain browsers.
Now I've been using Ape-Project.org and last night I had success!
I'm working on polishing things up so I can post the info somewhere.
Essentially it uses native support when available, falling back to flash emulation if flash is installed, otherwise it falls back to websocket emulation/proxy with comet ape.
Works great!
It doesn't get in the way and allows you to code just against websocket on both the client and the server and allows you to support almost everyone.
I tried your example 1:1 on an Ubuntu installation in an VirtualBox @ Windows 7. Using the newest Chrome release I don't get an connection established.
ReplyDeleteSince cloning a git repository only worked with the http:// protocol and not with git:// I thought maybe ubuntu doesn't know what to do with the ws:// protocol. Could that be the reason for not getting an connection to the websocket server?
I wonder if you have any idea or tip for me how to go on? Would really appreciate that!
Best regards from Austria
@David:Wie geht's? :) I'm not sure, but I think the protocol portion of a URL is handled by the browser, not the OS. Are you using an up-to-date chrome install? They added websocket support back in December: http://blog.chromium.org/2009/12/web-sockets-now-available-in-google.html
ReplyDeleteI'll try it out on Ubuntu (I did this all on OSX) later and see if I can reproduce your problem. Also, NodeJS has gone through some major API changes since I wrote this so the server code could be out of date too.
Es geht gut! Bei dir auch alles okay?
ReplyDeleteYeah Chrome is up to date. Freshly downloaded and installed. I found someone with an OSX so I will try your example there and if it's still not working I finally have a reason to get really into nodejs :)
This looks intersting. One question I have is on large scale of users, is there any suggestions/thoughts on how to deal with sending out the notifications in a more parallel fashion? Looping through 10,000 users seems inefficient
ReplyDelete@rooster 808: If the connection.write() method is blocking, then yes, it's a huge bottleneck. I think in this case it's async though, which means your overhead is a 10,000 item for-loop which is basically instantaneous on modern hardware. Hmm. Though you'd still have 10,000 copies of the written data (one byte array per server connection), but you could optimize that by sharing a single output byte array with multiple write counter positions (one counter per server connection). And free up the write buffer once the last writer is done.
ReplyDeleteIf you wanted to do like 10MM clients then perhaps you'd want to shard the websocket server connections over multiple machines, and have some kind of ipv6 multicast backchannel for the servers to broadcast updates to eachother (and then to their respective clients). Frankly I haven't given much thought to that particular problem but it's certainly a great question.
@robert, did you post your code somewhere? I'm interested in it, thanks!
ReplyDelete@newyuppie:
ReplyDeleteNo, I didn't. The code with ape-project worked and I even launched a website with it, but the site didn't get very much traffic and after a few months I shut it down.
I wouldn't use ape-project or my code again.
This is because I feel the right approach is to use: http://socket.io/
This basically does the same thing my code did. Uses WebSocket natively if available, falling back to flash if available, finally falling back to comet techniques.
A IEEE project is an interrelated arrangement of exercises, having a positive beginning and end point and bringing about an interesting result in Engineering Colleges for a particular asset assignment working under a triple limitation - time, cost and execution. Final Year Project Domains for CSE In Engineering Colleges, final year IEEE Project Management requires the utilization of abilities and information to arrange, plan, plan, direct, control, screen, and assess a final year project for cse. The utilization of Project Management to accomplish authoritative objectives has expanded quickly and many engineering colleges have reacted with final year IEEE projects Project Centers in Chennai for CSE to help students in learning these remarkable abilities.
DeleteSpring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai
AngularJS Training in Chennai AngularJS Training in Chennai Node.js Training in CHennai Angular 2 Training in Chennai Angular 2 Training in Chennai Node.js Training in CHennai Node.js Training in chennai MEAN Developer Training in Chennai
ReplyDeleteBackBoneJS Training in Chennai BackBoneJS Training in Chennai EmberJS Training in Chennai EmberJS Training in Chennai
Interesting Article
ReplyDeleteJavaScript Training in CHennai HTML5 Training in Chennai HTML5 Training in Chennai JQuery Training in Chennai JQuery Training in Chennai JavaScript Training in Chennai JavaScript Training in Chennai
JavaScript Training in CHennai JavaScript Training in CHennai JQuery Online Training JQuery Online Training
Interesting Article
ReplyDeleteJavascript Training in Chennai | HTML5 Online Training
JavaScript Training Courses | Javascript Online Training | Angular 2 Training in Chennai
discount oakley sunglasses
ReplyDeleteugg boots
moncler outlet online
pandora charms
longchamp sale
nike blazer low pas cher
michael kors outlet online
jimmy choo shoes
hejixia20161202
Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging, AC Market Download
ReplyDeleteThis is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information... AppValley
ReplyDeleteAll the contents you mentioned in post is too good and can be very useful. I will keep it in mind, thanks for sharing the information keep updating, looking forward for more posts.Thanks chatrooms
ReplyDeleteshowbox offers free movies and TV shows for free and the best part is that you can download them and watch them later.
ReplyDeleteTutuApp APK iOS Free Download Latest Version 2019 Best Version Free! here And Also more...
ReplyDeleteTutuApp iOS
TutuApp Lite
Aptoide for PC
ReplyDeleteMua vé máy bay tại đại lý vé Aivivu, tham khảo
ReplyDeletevé máy bay đi Mỹ
mua vé máy bay từ mỹ về việt nam hãng eva
vé máy bay từ đức về sài gòn
vé máy bay từ nga về việt nam bao nhiêu
replica bags paypal replica bags canada 7a replica bags meaning
ReplyDelete