Show HN: Multiplayer NES Server in 77 Lines of Go
1–10 of 21 posts
Re: Show HN: Multiplayer NES Server in 77 Lines of Go
#2Re: Show HN: Multiplayer NES Server in 77 Lines of Go
#3Re: Show HN: Multiplayer NES Server in 77 Lines of Go
#4 import (
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
"github.com/olahol/melody"
"net/http"
"sync"
)
But still impressive.Re: Show HN: Multiplayer NES Server in 77 Lines of Go
#5Is there any documentation around? I have no idea how any of this code works, and it doesn't seem to similar to the web apps that I have seen before. Haven't worked with melody before either...
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.
Re: Show HN: Multiplayer NES Server in 77 Lines of Go
#6mmm, not sure if doing this counts as using 77 lines of code: import ( "github.com/gin-gonic/gin" "github.com/gorilla/websocket" "github.com/olahol/melody" "net/http" "sync" ) But still impressive.
Re: Show HN: Multiplayer NES Server in 77 Lines of Go
#7Re: Show HN: Multiplayer NES Server in 77 Lines of Go
#8What's the best solution in Go to support graceful degradation for browsers without websockets / networks that disallow it?
Re: Show HN: Multiplayer NES Server in 77 Lines of Go
#9mmm, not sure if doing this counts as using 77 lines of code: import ( "github.com/gin-gonic/gin" "github.com/gorilla/websocket" "github.com/olahol/melody" "net/http" "sync" ) But still impressive.
Also the NES emulation is done in Javascript, making the 77 lines a little less impressive. It's "just" server for handling multiplayer part.