Show HN: Multiplayer NES Server in 77 Lines of Go
github.com
github.com
import (
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
"github.com/olahol/melody"
"net/http"
"sync"
)
But still impressive. import (
github.com/olahol/melody-jsnes
)* Clear and easy interface similar to net/http or Gin with event handlers.
* A simple way to broadcast to all or selected connected sessions.
* Message buffers making concurrent writing safe.
* Automatic handling of ping/pong and session timeouts.
Although it would be a cool thing to make a production ready web hosted multiplayer NES.
The implementation of the multiplayer itself is very simple and consists of these steps:
* Pair up players using a map from one session to another.
* Start an instance of https://github.com/bfirsh/jsnes on Player 1
* Screenshot the canvas of JSNES using toDataUrl.
* Send the screenshot to Player 2 and render it into a canvas.
* Send Player 2's keyup and keydown event's to Player 1.
The communication over the WebSocket is very fast, the screenshot is being sent at 30 frames per second.
Melody is just a small framework to make WebSockets easier to work with.