This is the primary repository for HTML WebSocket compatibility in Monkey2. This grants you the ability to be able to communicate with a properly setup WebSocket server from a Monkey2 application. Currently, this module only supports the Emscripten export and has only been tested with WASM selection.
video: WebSockets demo
- download this repository as a zip
- Move the zip into your monkey2 modules folder and unzip into its appropriate folder
- inside Ted2Go right click the folder and build this module for emscripten
See the demo for a quick usage test
- Chose emscripten wasm for export
- After it has been built run a simple web server of your choice in the directory
- You can find a simple server to use here. Just click on MServer
- Open up your browser and navigate your browser to a localhost, I usually use localhost:8080
Including sockets and extending the class
#Import "<html-ws>" ': HTML WebSockets now available
Using html.ws.. ': Access elements in global scope
Class DemoSock Extends WebSocket
Method New()
Super.New("ws://echo.websocket.org/") ' we provide the WS url, we can also add some WS protocols later if we want
End
Message retrieval hooks
Method OnData(data:String) Override ' this method passes us information recieved from the server
AddMessage( "Recieved: " + data )
End
Method OnOpen() Override ' After we've established a connection we can do some setup
AddMessage("Socket established connected!")
End
Method OnClose() Override ' We can start closing things up or reacting to a disconnection here
AddMessage("Socket terminated!")
End
Nothing decided for now as far as a standard. I'm learning a style of my own as I go. Please do fork, please do comment, please do add tickets, please do offer suggestions. Everything's welcomed!
- Abe Noll - Initial work - Forgotten King
This project is licensed under the MIT License - see the LICENSE.md file for details