Code Monkey home page Code Monkey logo

websocket-chat's Introduction

これはなに

go/websocketでchatの実装
一応グループチャットをサポート

セットアップ

パッケージ管理にglideを使っているので、
$GOPATH/srcに配置しないといけません。

cd $GOPATH/src
git clone [email protected]:inosk/websocket-chat.git
cd websocket-chat
go build

使い方

cd $GOPATH/src/websocket-chat
go build
./websocket-chat

コードの説明

コレの写経 https://github.com/gorilla/websocket/tree/master/examples/chat

理解のためにコメントを追加

  • main.go
    • ただのhttpサーバ
  • hub.go
    • clientを管理するための構造体
      • clientの参加や離脱を管理している
    • client間はhubを通じてmessageのやり取りをする
    • hubを経由したbroadcastのみをサポート
  • client.go
    • チャット参加者を表現する構造体
    • readPumpはユーザからの入力をwebsocket経由で受け付けてbroadcat channelに投げる
    • writePumpはwebsocketからのsendを受け付けて画面に表示するためのイベント発行
  • room.html.tmpl
    • フロントエンド
    • onmessageで受信したmessageのdivを作ってbodyに挿入

websocket-chat's People

Contributors

inosk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.