Skip to content
Back to skills

Websocket Development

ASecurity

--- name: websocket-development description: Implement real-time communication using WebSockets and Socket.io ---

  • 33 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added February 10, 2026
developmenttypescriptreacttestingapisecurity

Works with

  • cli
  • api

Security analysis

A100/100

Scanned February 12, 2026

npx -y skills add lovedragonball/power-ranger-toolkit --skill websocket-development --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Websocket Development?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Websocket Development
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/lovedragonball-websocket-development/badge)](https://www.skillsdirectory.com/skills/lovedragonball-websocket-development)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# 🔌 WebSocket Development Skill

---
name: websocket-development
description: Implement real-time communication using WebSockets and Socket.io
---

## 🎯 Purpose

พัฒนา real-time features โดยใช้ WebSockets และ Socket.io

## 📋 When to Use

- Chat applications
- Live notifications
- Real-time updates
- Collaborative editing
- Gaming
- Live dashboards

## 🔧 Implementation

### Server (Socket.io)
```typescript
import { Server } from 'socket.io';

const io = new Server(server, {
  cors: { origin: '*' }
});

io.on('connection', (socket) => {
  console.log('User connected:', socket.id);
  
  // Join room
  socket.on('join', (room) => {
    socket.join(room);
  });
  
  // Handle message
  socket.on('message', (data) => {
    io.to(data.room).emit('message', data);
  });
  
  // Disconnect
  socket.on('disconnect', () => {
    console.log('User disconnected:', socket.id);
  });
});
```

### Client (React)
```typescript
import { io, Socket } from 'socket.io-client';
import { useEffect, useState } from 'react';

function useSocket(url: string) {
  const [socket, setSocket] = useState<Socket | null>(null);
  const [messages, setMessages] = useState<Message[]>([]);
  
  useEffect(() => {
    const newSocket = io(url);
    setSocket(newSocket);
    
    newSocket.on('message', (msg) => {
      setMessages(prev => [...prev, msg]);
    });
    
    return () => { newSocket.disconnect(); };
  }, [url]);
  
  const sendMessage = (content: string) => {
    socket?.emit('message', { content, timestamp: Date.now() });
  };
  
  return { messages, sendMessage, connected: !!socket };
}
```

## 📊 Event Patterns

| Event | Direction | Use Case |
|-------|-----------|----------|
| `connect` | Server→Client | Connection established |
| `disconnect` | Server→Client | Connection lost |
| `message` | Bidirectional | Send/receive messages |
| `join` | Client→Server | Join a room |
| `leave` | Client→Server | Leave a room |
| `broadcast` | Server→All | Send to all clients |

## 🔒 Security

```typescript
// Authentication middleware
io.use((socket, next) => {
  const token = socket.handshake.auth.token;
  if (validateToken(token)) {
    socket.data.user = decodeToken(token);
    next();
  } else {
    next(new Error('Unauthorized'));
  }
});
```

## ✅ Best Practices

- [ ] Handle reconnection
- [ ] Implement heartbeat
- [ ] Secure with auth
- [ ] Rate limiting
- [ ] Error handling
- [ ] Room management

## 🔗 Related Skills

- `socket-io` - Socket.io specifics
- `api-design` - API patterns
- `testing` - Test real-time

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…