Introducing: HTML WebSockets for MX2! + GitHub

About Monkey 2 Forums Monkey 2 Projects Introducing: HTML WebSockets for MX2! + GitHub

This topic contains 8 replies, has 4 voices, and was last updated by  Richard Betson 7 months, 3 weeks ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #12344

    Abe _King_
    Participant

    First things first, the repo: https://github.com/forgotten-king/Monkey2-HTML-WebSocket/tree/Dev

    Hello, everyone! I’ve just finished developing a working Monkey2 port for WebSockets. This is purely a JavaScript wrap and not available for other exports. Being that this is my first C++ project and third* (2nd) real Monkey2 project this may be a bit rough around the edges. It is currently implemented as a near 1 to 1 implementation with actual HTML5 sockets minus a few smaller things IE:can only send strings, there is also a potential memory flaw with retrieving malocc’d strings from JavaScript.

    For anyone interested, once the Module has been accepted it should eventually be accessible through the Modules as “html-ws” and under namespace html.ws. All documentation for this implementation will be found in the main monkey2 file, the C++ files are bare.

    As it stands, this is an introductory version, whatever that means, but will be usable in projects. I personally don’t have any problems with my implementation but I figure, hope, there will be suggestions and requests for the current API. I anticipate most comments will be about requesting a near 1 to 1 implementation for the native socket API. I’m not sure how possible it will be, but I will make my best attempt if enough people request or Mark himself prefer it over my current version.

    # Spoilers

    video: LINK (because thumbnail ruined quality)

    Code:

    #12351

    Pakz
    Participant

    So, what can you do with these websockets and games? Is it for multiplayer game like quake in the webbrowser and such?

    #12353

    Abe _King_
    Participant

    To answer your question: Yes! If you wanted to make a multiplayer game like quake for browsers WebSockets are the way to go!

    To add more details about web sockets:
    The reason WebSockets are so important is that they’re currently the most widely supported way of real-time communication from the browser. I can’t explain it better than other articles out there, but for Monkey2 it means you can now have real-time (web)socket based applications in your browser games – which is actually not currently supported in Monkey2 – excluding this module.

    Perhaps you wanted to make an online chat room on Monkey2. It can be done multiple ways, but WebSockets were introduced because of the rising demand of real-time connected applications.
    So it would look like this:
    1. Create a server in a language which has some web-socket host libraries. JavaScript is a good candidate though not what I use.
    2. Once your server is set up to handle web sockets, it’s time to make your client
    3. All you have to do is extend the WebSocket class and define some handles and you’re essentially done!

    #12367

    Richard Betson
    Participant

    I’ll be checking this out. 🙂

    #12491

    Abe _King_
    Participant

    Update for everyone whos been wanting to try it out! I’m not sure how long it will be until my module is excepted but here is the repository! Feel free to dig/play around! The banana should include everything you need to start out with. Feel free to ask questions here or on the issues of the repo.

    Github: https://github.com/forgotten-king/Monkey2-HTML-WebSocket/tree/Dev

    #12511

    Xaron
    Participant

    Awesome, this is just great, thanks!

    #12535

    Xaron
    Participant

    Hey Abe, so it should be possible to create a server application in MX2 which listens to classic sockets plus websockets? As far as I understood this stuff you just need to react in a different way, so you have to send back kind of a http header during connect?

    #12537

    Abe _King_
    Participant

    @xaron As far as I’m aware, that should be completely possible. I’ve actually done it in a different language if you’d like to see! Though, the WebSocket transformations were apart of a standard library in the language. But if you would like to learn more about making a WebSocket server that is the base idea. You can find out more here https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers

    I will probably be making a WebSocket transformation API sometime in the future, but it’s not a priority of mine at the time being. I can try taking a look at it sooner than later if you’d like! It wouldn’t be a part of this API though

    #15332

    Richard Betson
    Participant

    Got the demo working on Linux. 😀 Playtime!

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.