Basic
Multiplayer Online Game
with Node.js & dgt-net
Pisit Tangkoblarp (King)
pisit@digitopolisstudio.com
Lead Engineer
Digitopolis Co., Ltd.
Me
• CprE@1 Kmutnb
• 2007 - Present 

Digitopolis Co., Ltd.
• Junior > Senior > Lead Engineer
• PC Apps & Games

Mobile Apps & Games

Backends & Servers

Databases & Caches
Pisit Tangkoblarp (King)
pisit@digitopolisstudio.com
Our Story
Found in 2007
2013
2015
2016
2014
App & Game
Development
Services
Online Game Anatomy
• Client
• Server
• Database
• Tools - Game Operations, Customer Support, Analytics, etc.
Online Game Engines
• Big World Engine - http://bigworldtech.com
• HeroEngine - http://www.heroengine.com
• photon - https://www.photonengine.com
• SmartFox - http://www.smartfoxserver.com
• OMG - Debuz Co., Ltd.
• Pomelo - http://pomelo.netease.com
Write your own
• C, C++
• C#, Java
• Node.js, Go
• socket.io, dgt-net
Network Programming
• 7 Layers OSI Model
• Socket
• IP/Port
• TCP/UDP
• Listen/Connect
Multithreaded Programming
• Fork
• Join
• Lock
• Asynchronous
Why Node.js?
• Based on C++
• Solid Foundation:
• Chrome’s V8 JavaScript Engine
• Network
• Asynchronous Non Blocking Model (Event Loop)
• Free!
Why dgt-net?
• Thin network layer on top of Node.js
• Managed TCP connection & buffering
• Protocol that minimize network bandwidth
• Light & Fast
dgt-net
• packet_writer Class
• packet_reader Class
packet_writer
• append_string(data)
• append_uint8(data)
• append_uint16(data)
• append_uint32(data)
• append_int8(data)
• append_int16(data)
• append_int32(data)
• append_float(data)
• append_double(data)
• finish()
packet_reader
• read_string()
• read_uint8()
• read_uint16()
• read_uint32()
• read_int8()
• read_int16()
• read_int32()
• read_float()
• read_double()
• completed()
The Packet
uint16 uint16 int8 int16 int32 float uint16 uint8
Packet Header (2 Bytes)
Packet ID (2 Bytes)
Binary Stream (Byte Array)
Visualization
1 Byte
Payload Data
The Packet
18 10001 -50 -30,000 -2,000,000,000 15.05 50,500 19
Packet Header (2 Bytes)
Packet ID (2 Bytes)
Binary Stream (Byte Array)
Sample Data
1 Byte
Payload Data
The Packet
18 10002 H e l l o W o r l d ! ! 0
Packet Header (2 Bytes)
Packet ID (2 Bytes)
Binary Stream (Byte Array)
Sample Data
Null Terminate String
Payload Data
dgt-net
• server.RemoteProxy Class
• client.Remote Class
Remote & RemoteProxy
• onConnected()
• onDisconnected()
• send(data)
• Handle packet’s command
• Hold underlying socket object
Remote & RemoteProxy
• Create your own Remote & RemoteProxy classes by EXTENDS
client.Remote & server.RemoteProxy classes
dgt-net
• server Object
• client Object
dgt-net
• let server = require(‘dgt-net’).server

server.setRemoteProxyClass(MyRemoteProxy)

server.setPacketObject(packetServer)

server.listen(port)
• let client = require(‘dgt-net’).client

client.setRemoteClass(MyRemote)

client.setPacketObject(packetClient)

client.connect(host, port)
The PacketObject Pattern
• Define Packet IDs
• Process received packets
• Make packets
Install dgt-net
• npm install dgt-net —save
dgt-net_demo
• https://github.com/0angelic0/dgt-net_demo
What to be concerned?
• Performance
• Scalability
• Security
• Availability
What to be concerned?
• Database
• Caching
• Monitoring
• Interpolation & Prediction Movement
Thank You
Have fun!

Basic Multiplayer Online Game with Node.js & dgt-net