Installable skillMIT

30-example-network-server

Status: ACTIVE AppliesTo: v10 Type: GUIDE

BY devwinsoftUPDATED Oct 27, 2026
INTENDED FOR◈OpenClawInstall in a listed agent.

instructions.md

---
name: 30-example-network-server-game-protocol-ts
description: "Status: ACTIVE AppliesTo: v10 Type: GUIDE"
---

# 21-game-server-ts — Game Protocol TS 서버 예제

Status: ACTIVE
AppliesTo: v10
Type: GUIDE

---

## Scope / Purpose

Game protocol 기반 TypeScript **서버** 예제.

Devian 네트워크 서버 조립 방식과 ServerRuntime 사용법을 보여준다.

---

## 경로 SSOT

| 구분 | 경로 |
|------|------|
| **Server** | `framework-ts/apps/GameServer/` |

---

## 핵심 조립 포인트

```typescript
import { WsTransport, NetworkServer } from '@devian/core';
import { createServerRuntime, Game2C } from '@devian/protocol-game/server-runtime';

// 1. Runtime 생성
const runtime = createServerRuntime();

// 2. Stub 획득 (핸들러 등록용)
const stub = runtime.getStub();

// 3. Transport 생성
const transport = new WsTransport({ port: PORT }, {
    onBinaryMessage: (sessionId, data) => server.onBinaryMessage(sessionId, data),
    // ...events
});

// 4. NetworkServer 생성
const server = new NetworkServer(transport, runtime, {
    onUnknownInboundOpcode: async (event) => {
        // unknown opcode 처리 (disconnect 없이 로깅만)
        console.warn(`Unknown opcode ${event.opcode}`);
    },
});

// 5. Outbound Proxy 생성 (타입 안전)
const game2cProxy = server.createOutboundProxy<Game2C.Proxy>();

// 6. Handler 등록
stub.onPing(async (sessionId, msg) => {
    await game2cProxy.sendPong(sessionId, { ... });
});
```

---

## 코덱 전환 (USE_JSON)

```typescript
import { defaultCodec as jsonCodec } from '@devian/core';

// false = Protobuf (default), true = Json
const USE_JSON = false;

const runtime = USE_JSON ? createServerRuntime(jsonCodec) : createServerRuntime();
```

- **기본값**: Protobuf (바이너리, 성능 우선)
- **Json 옵션**: 디버깅/테스트용

---

## 실행 방법

```bash
npm -w GameServer run start
```

---

## 설정

| 항목 | 기본값 | 비고 |
|------|--------|------|
| Port | `8080` | WsTransport 바인딩 포트 |
| Unknown opcode | 로깅만, disconnect 안함 | `onUnknownInboundOpcode` 훅 |

---

## Related

- [11-game-client-ts](references/upstream/dd8589e9bd7c081b-SKILL.md) — Game Protocol TS 클라이언트 예제
- [03-ssot](references/upstream/f275a4423d705682-SKILL.md) — Example Apps SSOT
- [30-protocol-game](references/upstream/bdab6f3e1ae3946f-SKILL.md) — Game Protocol 예제
- [Protocol SSOT](references/upstream/276743c36cb3e46c-SKILL.md) — Opcode/Tag, Protocol UPM
COMPATIBILITY & REFERENCES

Platform guidance

Imported from the listed AgentSkill.sh category. Complete supplied package files and notices are retained. Required external tools and credentials are not installed. No bundled code was executed during import. Individual agent task behavior has not been tested.

Resource notes updated 2026-10-27 · Original instructions by devwinsoft