本文整理匯總了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
}
}
}