当前位置: 首页>>代码示例>>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;未经允许,请勿转载。