Performance Optimization
Optimize Broadcast Frequency
Optimize Broadcast Frequency
Don’t broadcast on every state change. Batch updates and limit frequency:
Use Delta Time for Smooth Movement
Use Delta Time for Smooth Movement
Always use delta time to ensure consistent behavior across different tick rates:
Minimize Broadcast Payload Size
Minimize Broadcast Payload Size
Only send data that changed, not entire state:
Adjust Tick Rate Based on Game Type
Adjust Tick Rate Based on Game Type
Different games need different tick rates:
Client-Side Prediction
Client-Side Prediction
Update local state immediately, then reconcile with server:
Security Best Practices
Validate All User Input
Validate All User Input
Never trust client data - always validate on the server:
Implement Rate Limiting
Implement Rate Limiting
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.
Sanitize User Content
Sanitize User Content
Clean user-generated content before broadcasting:
State Management
Initialize State Properly
Initialize State Properly
Always check if state exists before using it:
Clean Up Disconnected Players
Clean Up Disconnected Players
Remove player data when they disconnect:
Use Session Data for Player-Specific Info
Use Session Data for Player-Specific Info
Store per-player data in session, not room state:
Handle State Synchronization
Handle State Synchronization
Ensure all players have consistent state:
Error Handling
Handle Errors Gracefully
Handle Errors Gracefully
Catch and handle errors to prevent crashes:
Provide Clear Error Messages
Provide Clear Error Messages
Help users understand what went wrong:
Handle Reconnections
Handle Reconnections
Allow players to reconnect and resume their session:
Scalability Tips
Limit Room Size
Limit Room Size
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
Implement Room Sharding
Implement Room Sharding
Split large player bases across multiple rooms:
Clean Up Inactive Rooms
Clean Up Inactive Rooms
Destroy rooms when empty:
Use Database for Persistence
Use Database for Persistence
Store important data in the database, not just room state:
Testing & Debugging
Add Debug Logging
Add Debug Logging
Use print statements to debug issues:
Next Steps
API Reference
Complete API documentation
Examples
Full example games and applications
