Websocket library -- Make your own Websocket server

Hi all,

I've recently created a library that allows a Processing sketch to act as a Websocket server. This is in the opposite direction of making the sketch communicating to a server running Node.js or so, and hopefully can give you guys more control in using Processing :D

Along with it is an interesting example which allows one to use a mobile phone to wirelessly control the box drawn in the sketch. All you need is just a place to host the html file and a computer that runs Processing.

The library and code are available through GitHub now: https://github.com/thisisvictor/WSProcessor

If possible I'd like to make it available through the Processing>Library. Please let me know how this can be done, or should I be contacting anyone in particular.

Questions and comments are welcome. This is my first time making Processing library so please pardon me for missing any important info.

Thanks and have fun!




  • edited September 2014

    Nicely coded, @thisisvictor! :-bd

    Due to Processing's community tweak-ish nature, it'd be gr8 if you'd restrain declaring class' members as private though.
    Ya know, protected access is more balanced, as it allows subclassing while disallows direct manipulation! (*)

    Also, those last utility methods could be all declared static, since they don't directly access class' members!
    And I believe there's no danger at declaring some of them public as well!
    Who knows it might be useful outside your own library! ;;)

  • Thanks for the kind words and suggestions @GoToLoop.

    When I made those attributes and methods I was just factoring them out from a chunk of steps, so I didn't think about subclassing. I've made all the helper methods protected as suggested. I however still want to keep them fairly limited within the class because they rely on correctly setting up the bytes, mask, and what-not, thus a random call to those methods from outside would likely lead to troubles. With some careful planning some might indeed be static, but I guess I'm just too lazy to worry about that ;)

    The only one method that might be useful is the bitAt(byte, int), which I've made public static.

  • edited September 2014

    Thx for allowing us to tweak it if we needed to! ^:)^

  • Hi thisisvictor, you did a great job! I just quickly set up a websockets server using your library and almost everything works fine. The only problem I encountered is in the communication from server to client: WSprocessor.sendMessage() works only the very first time. After that I got "Client SocketException: Connection reset stopping the connection" and can't send any further message to the client. I'm using Processing 3, maybe you know how to fix this? Actually my main goal is to send message from server to many clients. Thank you in advance for any answer...

Sign In or Register to comment.