TCP to WebSockets Tutorial
The Telnet to PAC-MAN Web Game is a tutorial that shows how to route real-time TCP messages between a TCP client (in this case a telnet client) and a browser. The communication is routed via the server that translates standard TCP messages to and from WebSocket Messages.
The game controller, which includes the telnet server, is designed entirely in the Lua scripting language. The game controller is responsible for proxying the traffic between the telnet client and the Pac-Man game running in the browser. The game controller's source code (Lua script) uses ready to use components such as the high level socket/websocket API.
How the Telnet to Pac-Man Server Works
- A browser navigates to the Pac-Man "game controller" running in the server.
- The Pac-Man game, which is completely implemented in JavaScript, is loaded into the browser.
- The browser loads all resources such as the MP3 sound files.
- The game's JavaScript code opens a persistent websocket communication channel with the server.
- The game is now ready to accept a telnet connection.
- A telnet client connects to the server.
- The game controller connects the two clients together and initiates the game.
- Keyboard events are sent from the telnet client to the Pac-Man game running in the browser via the game controller proxy.
- When the game ends, JavaScript code sends an event to the game controller, which then terminates the telnet connection.