Web Experiment: Shared canvas with Websockets

For today experiment I tryed to recreate the cool sketchpad by mr doob using websockets and HTML5Canvas.

The idea is that while you paint on the canvas your strokes are send to the server and broadcast to all the users on the web in realtime using websockets, you also can see the cursor of the other people. Click on the image to test it but remember that if there are not other users online you will be just drawing alone.

Shared Canvas

If you want to know more about the coding read the full post.

Server side

I’ve been trying for a long time to make an app using websockets, but it turned out to be harder than it should be, mainly because the standard has been changing constantly for the last year so it was hard to find libraries to use on the server side to abstract me from the protocol, I even tryed to coded by myself but there was some binary info being exchanged that I couldnt handle.

I wanted to code a simple broadcast server. I’ve done it before in python but for this time I wanted to use node.js, I really think that nodejs is a great idea. I understand why some people hesitate, but the truth is that it allows to prototype apps really fast thanks to a good API and the benefits of using the same code on the server and the client.

I’ve tryed to code a broadcast server in nodejs before, but all the libraries I tryed were giving me problems during installation, even using the node package manager. Everybody recommends to use socket.IO but I find that library too big and complex to use (it forces you to serve files to fallback in case the browser doesnt support websockets, which wasnt my case).

Finally I found one called faye-websockets that worked perfectly, nice sintax and support most of the version of the standard. It even creates an http server so you can use the same server to handle static files.

The server is really simple, every message gets resend to all the clients connected, it even allows to buffer the latest 100 messages so you can replicate the last part of the session when someone gets connected.

I was surprised by the performance, it will be nice to make a benchmark with several users but right now it seems it can handle a lot of concurrent users without problems.

And the coolest thing is that the server is totally blind to the app, so I can reuse it for any app I want in the future. I’m improving it so it allows a tiny protocol to store and retrieve info from the server.

Client side

Here nothing new, the user actions are transformed in messages and then processed by the painting app and sent to the server, so I dont have to code the behaviour of the users actions separately.

I experimented with different types of brushes but the HTML5 Canvas is limited, I wanted to tint an image and use it as a brush but the Canvas doesnt allow to tint an image, so I discarded that option).

The cool thing is that now I can add new types of user actions and the platform doesnt change, so to prove that I did cursor rendering on the screen of the other online users.

Persistent data

There is only one problem about the app, new users cant see the previous image (besides the buffered strokes which are just a few), so I’ve been thinking of an option that let the users send to the server the canvas image so the new users can download it, I can do that easily using the http server included with the library.

The server sets a DB where it can store data (just a name=>value storage). Clients can send data with a given name or retrieve it. This info is not persistent once the server is restarted (it can be easily dumped to a text file but I dont need it by now).

The only problem was that due to cross-server policies I wasnt able to access the HTTP server through ajax calls if the server were I hosted the app was not the own websocket-http server (which wasnt).

Luckly thanks to this wonderful site I was able to set the CORS policy info on the HTTP response header very easily just adding this field:

response.writeHead(status_code, {'Content-Type': 'text/plain', "Access-Control-Allow-Origin":"*"});

Another nice feature is that I can access my server through the browser typing an special url to check how many clients are online, useful to debug purposes. I even could create a tiny admin protocol to handle stuff.

 

Comments

2,966 responses to “Web Experiment: Shared canvas with Websockets”

  1. Deshi Sexx Avatar

    Explore DeshiSexx for online entertainment and adult-oriented content.
    Visit the website to discover its available content and enjoy a user-friendly browsing experience.

  2. webpage Avatar

    Hey this is kinda of off topic but I was wanting to know if blogs use WYSIWYG editors or if you
    have to manually code with HTML. I’m starting a blog soon but
    have no coding expertise so I wanted to get guidance
    from someone with experience. Any help would be enormously appreciated!

  3. karkasnyy_yjoa Avatar

    ?? ???????? ? ?????? ? ???????????? ?????? ??????? ??????????? ??????????? ????????????? ????????? ????? ??? — ??????????? ???????, ??????? ???????? ???????? ??? ?????????? ????? ? ?????-??????????.
    ????????????? ????????? ????? ???????? ???????????? ????? ?????, ?????????? ??????????? ?????????? .

    ????????? ???? ?????????? ?????? ????????? ??????? ????????????? ? ????????? ????? .

    ? ?????? ????????? ????? ????? ??????? ????, ??????? ????? ???? ??????????? ?? ????????? ??????????.

    ???????? ???????????? — ??? ??????? ????????????? ? ???????? ?????? ???? ?????? ?????????.

    ??? ?????? ????? ???????????? ? ????????? ????????, ????????? ?? ??????????????? ? ??????????? ?????????? .

    ???????? ???????, ? ???? ???????, ?????? ?????????????? ??????? ? ??????? ???? ?????????? ???.

    ????????????? ????????? ????? ????????? ??????????? ????????? ????? ????? ?? ????????? ? ?????????? ??? ????????? ???????? .

    ??? ????????????? ????? ????????? ????????? ???????????????? ???????????? ?????? ? ?????? .

    ????????? ???? ???????? ??????????? ??????? ??? ???, ??? ????? ???????? ? ???????? ?????????? .

  4. karkasnyy_trMi Avatar

    ???? ?? ????? ???????????? ? ????????? ????????? ??? ??? ???? — ???? ??????????? ?????? ????????? ???? ???? ? ?????????? ?????? ? ???????.
    ????????????? ????????? ????? ?????????? ??? ????? ?????????? ????????? ????? ???????? ? ???????????.

  5. ??????? ?????? ??????????? ???? ??????? Avatar

    Howdy terrific blog! Does running a blog like this require a large amount of work?
    I have absolutely no understanding of coding but I had been hoping to start
    my own blog in the near future. Anyways, if you have any recommendations or
    tips for new blog owners please share. I know this is off subject but
    I simply had to ask. Appreciate it!

  6. 32WIN Avatar

    Do you have a spam problem on this blog; I also am a blogger,
    and I was wanting to know your situation; many of us have
    developed some nice practices and we are looking
    to trade solutions with other folks, please
    shoot me an email if interested.

  7. search console sitemap Avatar

    I work with many useful Seo instruments that help enhance web site site visitors and improve search rankings.
    Google is aware of this, so it provides a “Question and Answers” block
    earlier than the first SERP result, most likely diverting a tremendous quantity of
    site visitors away from that page. Honors for that high web page
    go to Ben Farrell at Data Driven Daily- Ben if you are reading
    I’d love to know the backstory of how you discovered this keyword and the way a lot
    site visitors it really drives! • Ahrefs / SEMrush:
    Keyword research, backlink analysis, and competitor tracking.
    Some analysis firms that specialize in key phrase analysis
    embody SEMrush, Ahrefs, and Moz. Yow will discover information about the final word Seo
    technique from trusted sources like Google’s Search Central Blog, industry leaders like Moz, Ahrefs,
    SEMrush, and from skilled businesses like Great Impressions, who simplify Seo into
    actionable, actual-world steps. Identify key phrases whose search engine rating is realistically
    obtainable by Seo. Backlinks are links from different websites that
    time to your webpage, performing as signals of belief and authority
    for engines like google. Furthermore, these links might result in websites
    or hyperlinks that comprise offensive and objectionable
    content or which can comprise harmful laptop viruses.

  8. karkasnyy_pdoa Avatar

    ?? ???????? ? ?????? ? ???????????? ?????? ??????? ??????????? ??????????? ????????????? ??? ????????? ??? ???? — ??????????? ???????, ??????? ???????? ???????? ??? ?????????? ????? ? ?????-??????????.
    ????????? ??? ?????????? ??? ????? ?????????? ? ??????????? ????????????? .

    ????????? ???? ?????????? ?????? ????????? ??????? ????????????? ? ????????? ????? .

    ??????? ?????????? ???? ???????? ??????? ????????? ?????????, ??????????? ?? ?????? ??? ??????? .

    ???????? ???????????? — ??? ??????? ????????????? ? ???????? ?????? ???? ?????? ?????????.

    ??? ?????? ????? ???????????? ? ????????? ????????, ????????? ?? ??????????????? ? ??????????? ?????????? .

    ?????? ???????? ????????? ?????? ?????????? ??? ????????? ? ???????? ??????? .

    ????????????? ????????? ????? ????????? ??????????? ????????? ????? ????? ?? ????????? ? ?????????? ??? ????????? ???????? .

    ?????????? ???????????? ? ????????????? ?????? ???????? ???????? ??????????? ?? ?????? ????.

    ? ?????, ????????? ??? — ??? ??????????? ???????, ?????????? ? ???? ????????, ????????????? ? ??????? .

  9. generate trx address Avatar

    Please let me know if you’re looking for a writer for your site.
    You have some really good articles and I feel I would be a good asset.
    If you ever want to take some of the load off, I’d love to write some articles for
    your blog in exchange for a link back to mine. Please blast me
    an e-mail if interested. Regards!

  10. karkasnyy_uwMi Avatar

    ???? ?? ????? ???????????? ? ????????? ??? ????????? ??? ???? — ???? ??????????? ?????? ????????? ???? ???? ? ?????????? ?????? ? ???????.
    ????????????? ????????? ????? ?????????? ??? ????? ?????????? ????????? ????? ???????? ? ???????????.

  11. Danielcit Avatar
    Danielcit

    Business on the simplified tax system ????????????? ??????

  12. parties Avatar

    That is very interesting, You’re an excessively skilled blogger.
    I’ve joined your feed and look forward to searching for
    more of your great post. Additionally, I have shared your website in my social networks

  13. Danielcit Avatar
    Danielcit

    Business on the simplified tax system ???????? ???????????? ?? ???????

  14. karkasnyy_uaoa Avatar

    ?? ???????? ? ?????? ? ???????????? ?????? ??????? ??????????? ??????????? ????????????? ????????? ??? ???? — ??????????? ???????, ??????? ???????? ???????? ??? ?????????? ????? ? ?????-??????????.
    ? ??????????? ???? ???????????????? ????????? ????? ????????? ??????.

    ???? ??? ????? ?????????? ??????? ????????? ?????????? ? ????????????? ?????????????? .

    ??????? ?????????? ???? ???????? ??????? ????????? ?????????, ??????????? ?? ?????? ??? ??????? .

    ???????? ???????????? — ??? ??????? ????????????? ? ???????? ?????? ???? ?????? ?????????.

    ????????? ???? ??????? ???????? ??? ????????????? ??????? ? ????????? ?????? ? ?????? ????? .

    ???????? ???????, ? ???? ???????, ?????? ?????????????? ??????? ? ??????? ???? ?????????? ???.

    ? ??????? ?? ?????? ?????, ????? ???? ?????????? ?? ??????????? ?????, ??? ???????? ?????? ? ????? .

    ?????????? ???????????? ? ????????????? ?????? ???????? ???????? ??????????? ?? ?????? ????.

    ????? ??? ????????????? ???????? ???????? ??? ???, ??? ????? ?????? ???????? ?????? ? ???????? ???.

  15. ?????? ????? Avatar

    Woah! I’m really digging the template/theme of this blog.
    It’s simple, yet effective. A lot of times it’s hard to get that “perfect balance” between superb usability
    and visual appeal. I must say that you’ve done a awesome job with this.
    Also, the blog loads super quick for me on Internet explorer.
    Outstanding Blog!

  16. Cheap Usa Private Proxies Avatar

    Wow, this article is fastidious, my sister is analyzing such things, so I am
    going to let know her.

  17. aplikasi yang bisa merubah wajah Avatar

    Informationen zu aplikasi yang bisa merubah wajah finden Sie auf unserer AI Swap Face-Seite: https://aiswapface.ai/de/face-swap-app/. Wir betreiben diese Ressource.
    Für klare Ergebnisse empfiehlt sich ein scharfes, gleichmäßig beleuchtetes Ausgangsfoto mit einem ähnlichen Gesichtswinkel wie im Zielbild.

  18. karkasnyy_gcMi Avatar

    ???? ?? ????? ???????????? ? ????????? ??? ????????? ??? ???? — ???? ??????????? ?????? ????????? ???? ???? ? ?????????? ?????? ? ???????.
    ??? ????????????? ????????? ????? ????? ????????? ??????? ????????? ? ?????????? ??????.

  19. AirDoctor Air Purifier for Dust Avatar

    Oh my goodness! Incredible article dude! Thanks, However I am going through issues with
    your RSS. I don’t know the reason why I can’t join it.
    Is there anybody getting similar RSS issues? Anyone that knows the answer will you
    kindly respond? Thanks!!

  20. MartaDeste Avatar
    MartaDeste

    This dim light glided soft exposed body as girl lay open lazily slowly along those soft fabric covers, soft dark gaze focused toward viewer with the gentle, passionate curve.Her ran soft slender digit along smooth shape of bare shoulder, further below, teasing thin thin hem of fine soft fabric till fine lone string fell away her arm.Quiet gentle murmur left full full shape as she envisioned one gentle touch claiming the position, feeling each delicate with tender spot.Lifting soft shape, woman gave the full contour with bare curves, tight tips hardening from that power by one gaze only!Gently she spread those limbs, uncovering warm heat still even pulsed in anticipation before the contact.Warm gentle touch wandered inside inner, touching careful, teasing motions when woman whispered his call like a tender whisper.Step nearer,” lover spoke, soft sound rich through yearning — here moment every portion from this is under the.”
    Best AI Companion Apps With Genuine Widget or Home Screen Integration

  21. AirDoctor Air Purifier Avatar

    Hi mates, fastidious article and pleasant arguments commented here, I am truly enjoying by these.

  22. AirDoctor Air Purifier for Dust Avatar

    Hey there, You’ve done a great job. I’ll certainly digg
    it and personally recommend to my friends.
    I’m sure they will be benefited from this website.

  23. karkasnyy_pwMi Avatar

    ???? ?? ????? ???????????? ? ????????? ????????????? ????????? ????? ? ?????-?????????? — ???? ??????????? ?????? ????????? ???? ???? ? ?????????? ?????? ? ???????.
    ??????????? ?????????? ????????? ?????? ????????? ????????? ????? ? ??????, ??? ????????? ????? ?????????????.

  24. rape child on web Avatar

    Useful info. Lucky me I discovered your web site accidentally, and I’m stunned why this coincidence did not came about earlier!
    I bookmarked it.

  25. business sales website Avatar

    Hi! Do you know if they make any plugins to safeguard
    against hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any suggestions?

  26. karkasnyy_adMi Avatar

    ???? ?? ????? ???????????? ? ????????? ??? ????????? ??? ???? — ???? ??????????? ?????? ????????? ???? ???? ? ?????????? ?????? ? ???????.
    ???????????? ???????? ? ?????? ?????????? — ????? ????????????? ?????? ????.

  27. best online casinos australia Avatar

    Now I am going to do my breakfast, when having my breakfast coming again to read additional news.

  28. Microsoft Azure Avatar

    Howdy just wanted to give you a quick heads up. The words in your
    post seem to be running off the screen in Opera. I’m not sure if this is a
    format issue or something to do with web browser compatibility but I thought I’d post
    to let you know. The layout look great though! Hope you get the issue resolved soon.
    Many thanks

  29. webpage Avatar

    Hi there! Would you mind if I share your blog with my facebook group?
    There’s a lot of folks that I think would
    really enjoy your content. Please let me know. Thank you

  30. AirDoctor Air Purifier for Dust Avatar

    There is certainly a lot to learn about this issue.
    I love all the points you have made.

  31. karkasnyy_jtMi Avatar

    ???? ?? ????? ???????????? ? ????????? ????????? ???? ??? ??? ???? — ???? ??????????? ?????? ????????? ???? ???? ? ?????????? ?????? ? ???????.
    ? ?????????? ????? ????? ????????? ???????? ??? ????????? ????? ?????????.

  32. babu88 Avatar

    Undeniably believe that which you said. Your favorite justification seemed to be on the web the easiest thing to be aware of.

    I say to you, I certainly get annoyed while people think about worries that they plainly do
    not know about. You managed to hit the nail upon the top as well as defined out the whole thing without having
    side-effects , people can take a signal. Will
    probably be back to get more. Thanks

  33. ???? ??? Avatar

    Great article! That is the type of information that are supposed to be shared across the internet.
    Shame on Google for not positioning this put up
    higher! Come on over and seek advice from my website .

    Thanks =)

  34. Earth Day Avatar

    05 July 2009 (Honduras’ government has suspended fundamental human rights) Honduras’ government has
    declared an emergency and suspended basic human rights.

  35. Dannyclary Avatar

    ????????? ? ????? ???????, ?? ???????????? ???? ?? ?????????. ?????? ?????????? ?? ????? ??????????????, ?????? ?? ???????, ??? ????????????? ? ?????? ????????????. ?? ????? ???? ?????????? ??????? ????????????, ? ??????? ????? ??????? ?????? ? ????????????? ?? ???????. ??? ??? ???????? ????? ??? — ??? ?????? ?????? ????? ? ??? ????????????? ?????? ??????????? ???????? ?????????? ????? ?????? ???? ????? ??????????????

  36. karkasnyy_nuMi Avatar

    ???? ?? ????? ???????????? ? ????????? ????????? ??? ????? ????????? — ???? ??????????? ?????? ????????? ???? ???? ? ?????????? ?????? ? ???????.
    ???????????????? — ???? ?? ??????? ??????????? ????????? ????????, ??? ?????? ?? ???????? ???????????????? ? ???????? ????????? ??? ?? ??????????????.

  37. slot pop108 Avatar

    I couldn’t resist commenting. Exceptionally well written!

  38. LeroyFep Avatar

    ???????????? ????? ????? ??? ???? ?? ????? ??? — ?????????, ?? ? ???????. ? ????????? ?? ???? ?????? ?????? ???????, ?? ?????????? ??? ??????? ??????: ?? ??????? ???????? ????? ? ??????? ???????, ??????? ???????? ????????????? ???????? ???????? ? ???????. ???? ??????? ??????????, ???? ?????? ???????? ??????????, ? ??????????? ? ???????? ?? ???????? ??????. ??? ??????? ????? ? ????????? — ????????? ??? ??????????????? ??????????? ? ? ??? ????? ???????? ???????? ?? ??????? ??? ??????? ????? ?????

  39. ???? ?????? ??????????? ???? ??????? Avatar

    Thanks in support of sharing such a good thought, article is pleasant,
    thats why i have read it completely

  40. CBD dosage Avatar

    My developer is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the expenses.
    But he’s tryiong none the less. I’ve been using
    Movable-type on various websites for about a year and am nervous about
    switching to another platform. I have heard very good things about blogengine.net.
    Is there a way I can transfer all my wordpress posts into it?
    Any help would be really appreciated!

  41. pokerdom ?????? ??????????? ???? Avatar

    Excellent article. Keep writing such kind of information on your site.

    Im really impressed by your site.
    Hey there, You’ve done a fantastic job. I’ll certainly digg it and for my
    part suggest to my friends. I am sure they’ll be
    benefited from this site.

  42. ClydepleaR Avatar

    ?????????? ????? ??? ????????, ?? ????????? ????? ????????? ??????????? ??????? ?????????. ????????? ?????????????? ?????????, ???? ???????? ?????? ??????. ?????? ?? ???????, ????? ?????? ????? ??? ?????? ?????? ? ?????????? ???????????. ???????? ???????? ???????? ?????? ?????? ?? ???????. ??? ??????????? ? ????? ????????? — ? ??? ????????? ??????? ? ??? ??????? ?? ?????????? ???? ?????? ???? ???????????? ????????? ?????

  43. dewa 89 Avatar

    I know this if off topic but I’m looking into starting
    my own weblog and was curious what all is needed to get setup?
    I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very internet smart so I’m not 100% positive.
    Any suggestions or advice would be greatly appreciated.
    Thanks

  44. 789P Avatar

    Hello, nhà cái 789P ?ang là sân ch?i uy
    tín v?i giao di?n hi?n ??i. Trò ch?i ?a d?ng t? casino, kh uy?n mãi h?p d?n.
    Tôi th?y ?n ??nh, ai ?ang tìm nhà cái thì ??ng ký ngay nhé!
    789P

  45. bitadaroo Avatar

    Great post.

    Here is my page :: bitadaroo

  46. MichaelHAK Avatar

    SLAM-???????: ????????? ? ???????????????? ?????????????

    SLAM-??????? (Simultaneous Localization and Mapping) – ??? ??????????, ??????????? ?????? ? ??????? 3D-????????????? ? ???????????. ??? ????????? ????????? ????????? ????? ??????????? ????????????, ???????????? ????????? ??????????? ?????????????? ? ???? ????????????. ??? ?????????? ????? ?????????? ? ????? ?????? ????????, ?? ????????????? ? ??????????? ?? ????????????? ? ??????????? ??????????? ?????????.

    ??????? ??????:

    ? ?????? SLAM-???????????? ????? ??????? ????????????? ??????????? ? ?????????? ?????. ??????, ?????????? ????????? (?????, ??????, ???????????? ????????????? ????), ???????????? ? ????????????, ??????? ?????? ?? ?????????? ?????. ????? ??????? ????????? ???????????? ??? ?????? ??? ???????? 3D-?????? ? ??????????? ????????? ??????? ? ???????? ???????. ????? ????????, ??? ??? ?????? ?????? SLAM-??????? ????????? ??????????? “?????????” ? ????????????, ????????, ???? ????, ???????? ??????, ???????? ?? ????????????.

    ?????????? SLAM-????????:

    ??????????? ? ?????????????: ?????? ????????????? ?????? ? ??????????, ???????? BIM-???????, ???????? ???????? ?????????????.
    ?????????????: ????????? ??????? ? ??????????? ?????, ?????????? ???? ????????? ??? ?????????? ??????.
    ???????? ? ???????????: ???????? ???????????? ???? ?????????, ?????? ??????????????? ????????.
    ??????????? ??????????? ????????: ?????????? ????????? ? ???????????? ???????? ? ???????.
    ??????????? ?????????? ? ????: ???????? ???????????? 3D-??????? ??? ??????????? ?????.

    ???????????? SLAM-????????:

    ?????????????: ??????????? ????????? ????? ? ?????? ????, ??????????? ??? ???????? 3D-???????.
    ??????? ????????: ???????????? ????????? ? ?????? ?????? ?? ?????????? ????????????.
    ???????????: ????????? ??????????? ??????? ? ??????????????? ??????.

    SLAM-??????? ?????????? ??????? ???????????, ? ? ??????? ?? ?????? ??? ?????? ????????????? ?????????? ???? ??????????. ?????????? ??? ??????? ? ??? ?????? slam ??????

  47. ?????? ?? ??????? Avatar

    I have to thank you for the efforts you’ve put in penning this site.
    I really hope to see the same high-grade content by you in the future
    as well. In fact, your creative writing abilities has encouraged me to get my own, personal site now 😉

  48. 1?????? ?????? ??????????? ???? ?? ??????? Avatar

    Hello! Would you mind if I share your blog with my myspace group?
    There’s a lot of people that I think would really enjoy your content.
    Please let me know. Thank you

  49. web page Avatar

    After exploring a number of the blog posts on your site, I seriously appreciate your technique of writing a blog.
    I bookmarked it to my bookmark webpage list and will be checking
    back in the near future. Please check out my website as well and
    tell me what you think.

Leave a Reply

Your email address will not be published. Required fields are marked *