本文整理汇总了Golang中golang.org/x/net/websocket.Conn.IsServerConn方法的典型用法代码示例。如果您正苦于以下问题:Golang Conn.IsServerConn方法的具体用法?Golang Conn.IsServerConn怎么用?Golang Conn.IsServerConn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/net/websocket.Conn
的用法示例。
在下文中一共展示了Conn.IsServerConn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: webSocketHandler
/*
The socketHandler for the websocket connection.
Accepts the websocket, hands it off through the socketChan, and
waits until the socket is closed before exiting the function.
//TODO: Actually manage disconnections properly.
*/
func webSocketHandler(ws *websocket.Conn) {
//Notify the irc manager of a new websocket
log.Println("socketHandler starting")
defer log.Println("socketHandler exiting")
var client ircClient = newWSClient(ws)
//Authenticate websocket:
var user *iwcUser = nil
for user == nil {
client.SendMessage(irc.NewMessage("Enter a username."))
msg, err := client.ReceiveMessage()
if err != nil {
return
}
username := strings.TrimSpace(msg.String())
client.SendMessage(irc.NewMessage("Enter a password."))
msg, err = client.ReceiveMessage()
if err != nil {
return
}
password := strings.TrimSpace(msg.String())
user = authenticate(username, password)
if user != nil {
client.SendMessage("Successfully logged in.")
} else {
client.SendMessage(irc.NewMessage("Invalid username/password."))
}
}
newclients := getSessionNotifier(user.username)
if newclients == nil {
client.SendMessage("Unable to find session. Closing...")
log.Printf("Unable to find session for ", user.username)
return
}
//Notify the client what the user's current nick is
client.SendMessage(irc.NewMessage("NICK " + user.profile.nick.name))
newclients <- &client
for {
if ws.IsServerConn() {
time.Sleep(100 * time.Millisecond)
} else {
log.Println("!!!!socketHandler returning after IsServerConn returned false")
return
}
}
}