當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Conn.IsServerConn方法代碼示例

本文整理匯總了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
		}
	}
}
開發者ID:infina,項目名稱:ircwebchat,代碼行數:58,代碼來源:websocket.go


注:本文中的golang.org/x/net/websocket.Conn.IsServerConn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。