Game networking protocols, WebSocket/UDP implementation, latency optimization for real-time multiplayer
Implements real-time multiplayer game servers using WebSocket and UDP protocols with latency optimization. Claude uses this when building multiplayer games requiring networked player synchronization, protocol selection, or performance tuning.
/plugin marketplace add pluginagentmarketplace/custom-plugin-server-side-game-dev/plugin install server-side-game-dev-plugin@pluginagentmarketplace-game-serverThis skill inherits all available tools. When active, it can use any tool Claude has access to.
assets/config.yamlassets/websocket-server.jsreferences/GUIDE.mdreferences/PROTOCOLS.mdscripts/helper.pyscripts/network-test.shImplement real-time multiplayer networking with WebSocket, UDP, and latency optimization.
const WebSocket = require('ws');
class GameServer {
constructor(port = 8080) {
this.wss = new WebSocket.Server({ port });
this.players = new Map();
this.setupHandlers();
}
setupHandlers() {
this.wss.on('connection', (ws, req) => {
const playerId = this.generateId();
const player = { ws, state: {}, joinedAt: Date.now() };
this.players.set(playerId, player);
ws.on('message', (data) => this.handleMessage(playerId, data));
ws.on('close', () => this.handleDisconnect(playerId));
ws.on('error', (err) => this.handleError(playerId, err));
this.sendToPlayer(playerId, { type: 'connected', playerId });
});
}
handleMessage(playerId, data) {
try {
const msg = JSON.parse(data);
// Validate message structure
if (!msg.type) throw new Error('Missing message type');
this.processGameMessage(playerId, msg);
} catch (err) {
console.error(`Invalid message from ${playerId}:`, err.message);
}
}
broadcast(msg, exclude = null) {
const data = JSON.stringify(msg);
this.players.forEach((player, id) => {
if (id !== exclude && player.ws.readyState === WebSocket.OPEN) {
player.ws.send(data);
}
});
}
}
const dgram = require('dgram');
class UDPGameServer {
constructor(port = 7777) {
this.socket = dgram.createSocket('udp4');
this.clients = new Map(); // address:port -> client
this.sequence = 0;
this.socket.on('message', (msg, rinfo) => {
const key = `${rinfo.address}:${rinfo.port}`;
this.handlePacket(key, msg, rinfo);
});
this.socket.bind(port);
}
send(client, data, reliable = false) {
const packet = this.createPacket(data, reliable);
this.socket.send(packet, client.port, client.address);
}
createPacket(data, reliable) {
const seq = this.sequence++;
const header = Buffer.alloc(4);
header.writeUInt16LE(seq, 0);
header.writeUInt8(reliable ? 1 : 0, 2);
return Buffer.concat([header, data]);
}
}
| Protocol | Latency | Reliability | Use Case |
|---|---|---|---|
| WebSocket | 20-50ms | High | Web games, chat |
| UDP | 5-20ms | None | FPS, racing |
| QUIC | 10-30ms | Configurable | Modern hybrid |
| TCP | 30-100ms | High | Turn-based, MMO |
| Error | Root Cause | Solution |
|---|---|---|
| ECONNRESET | Client disconnect | Graceful handling |
| High latency | Network congestion | Enable delta compression |
| Packet loss | UDP unreliability | Add reliability layer |
| WebSocket timeout | Idle connection | Implement heartbeat |
# Check active connections
netstat -an | grep :8080 | wc -l
# Monitor bandwidth
iftop -i eth0 -f "port 8080"
# Capture packets
tcpdump -i eth0 port 8080 -w capture.pcap
describe('GameServer', () => {
let server, client;
beforeEach(() => {
server = new GameServer(8081);
client = new WebSocket('ws://localhost:8081');
});
afterEach(() => {
client.close();
server.close();
});
test('accepts connections', (done) => {
client.on('open', () => {
expect(server.players.size).toBe(1);
done();
});
});
test('broadcasts messages', (done) => {
client.on('message', (data) => {
const msg = JSON.parse(data);
expect(msg.type).toBe('connected');
done();
});
});
});
assets/ - Server templatesscripts/ - Network testing toolsreferences/ - Protocol guidesThis skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.