Skip to main content

Performance Optimization

Don’t broadcast on every state change. Batch updates and limit frequency:
Always use delta time to ensure consistent behavior across different tick rates:
Only send data that changed, not entire state:
Different games need different tick rates:
Update local state immediately, then reconcile with server:

Security Best Practices

Never trust client data - always validate on the server:
Protect against spam and abuse:
CocoCloud has built-in rate limiting of 60 messages/second per player, but you should implement stricter limits for specific actions.
Verify player permissions before executing critical actions:
Clean user-generated content before broadcasting:

State Management

Always check if state exists before using it:
Remove player data when they disconnect:
Store per-player data in session, not room state:
Ensure all players have consistent state:

Error Handling

Catch and handle errors to prevent crashes:
Help users understand what went wrong:
Allow players to reconnect and resume their session:

Scalability Tips

Room-based architecture scales horizontally - each room runs independently. Design your rooms to be self-contained.
Don’t put too many players in one room:
Recommended limits:
  • Fast-paced games: 2-10 players
  • MMO zones: 20-50 players
  • Chat rooms: 50-100 users
Split large player bases across multiple rooms:
Destroy rooms when empty:
Store important data in the database, not just room state:

Testing & Debugging

Use print statements to debug issues:

Next Steps

API Reference

Complete API documentation

Examples

Full example games and applications