Last active
December 10, 2015 02:48
-
-
Save tenntenn/4370388 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// クライアント | |
type Client struct { | |
// Websocketの接続情報 | |
ws *websocket.Conn | |
// サーバ | |
server *Server | |
// クライアントに送るメッセージを受け取るチャネル | |
ch chan *Message | |
// 終了リクエストを受け取るチャネル | |
done chan bool | |
} | |
// メッセージ送信チャネルのバッファサイズ | |
const channelBufSize = 1000 | |
// 新しいクライアントを作成します。 | |
func NewClient(ws *websocket.Conn, server *Server) *Client { | |
if ws == nil { | |
panic("ws cannot be nil") | |
} else if server == nil { | |
panic("server cannot be nil") | |
} | |
ch := make(chan *Message, channelBufSize) | |
done := make(chan bool) | |
return &Client{ws, server, ch, done} | |
} | |
// Websocketの接続情報を取得します。 | |
func (self *Client) Conn() *websocket.Conn { | |
return self.ws | |
} | |
// メッセージ送信用のチャネルを取得します。 | |
func (self *Client) Write() chan<-*Message { | |
return (chan<-*Message)(self.ch) | |
} | |
// 終了リクエスト受け付けるチャネルを取得します。 | |
func (self *Client) Done() chan<-bool { | |
return (chan<-bool)(self.done) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment