本文整理匯總了Golang中github.com/fzzy/sockjs-go/sockjs.Session類的典型用法代碼示例。如果您正苦於以下問題:Golang Session類的具體用法?Golang Session怎麽用?Golang Session使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Session類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SocketHandler
func (d *device) SocketHandler(s sockjs.Session) {
d.clients.Add(s)
defer d.clients.Remove(s)
for {
time.Sleep(d.delay)
m := s.Receive()
if m == nil {
break
}
js := message_in{}
err := json.Unmarshal(m, &js)
log.Print(js)
if err != nil {
log.Print(err)
}
fi, err := os.OpenFile(js.Name, os.O_WRONLY, 0666)
if err != nil {
log.Print(err)
}
//
_, err = fi.Write([]byte(js.Represent()))
if err != nil {
log.Print(err)
}
log.Print(js.Represent())
fi.Close()
}
}
示例2: echoHandler
func echoHandler(s sockjs.Session) {
for {
m := s.Receive()
if m == nil {
break
}
s.Send(m)
}
}
示例3: dataHandler
func dataHandler(s sockjs.Session) {
sockjsClients.Add(s)
defer sockjsClients.Remove(s)
for {
m := s.Receive()
if m == nil {
break
}
}
}
示例4: ChatHandler
func ChatHandler(s sockjs.Session) {
Users.Add(s)
defer Users.Remove(s)
for {
m := s.Receive()
if m == nil {
break
}
m = []byte(fmt.Sprintf("%s %s: %s", strings.Split(time.Now().Format(layout), " ")[1], username, m))
Users.Broadcast(m)
time.Sleep(5 * time.Second)
}
}
示例5: chatHandler
func chatHandler(s sockjs.Session) {
users.Add(s)
defer users.Remove(s)
for {
m := s.Receive()
if m == nil {
break
}
fullAddr := s.Info().RemoteAddr
addr := fullAddr[:strings.LastIndex(fullAddr, ":")]
m = []byte(fmt.Sprintf("%s: %s", addr, m))
users.Broadcast(m)
}
}
示例6: connHandler
func connHandler(s sockjs.Session) {
c, err := DialTLS("imap.gmail.com", nil)
if err != nil {
log.Fatal(err)
s.Send(err2byte(err))
s.End()
return
}
go func() {
for {
r, err := c.Receive()
if err != nil {
s.Send(err2byte(err))
continue
}
b, err := json.Marshal(r)
if err != nil {
s.Send(err2byte(err))
continue
}
s.Send(b)
}
}()
for {
m := s.Receive()
if m == nil {
break
}
cmd := &Command{}
err := json.Unmarshal(m, cmd)
fmt.Printf("%s\n%v\n", m, cmd)
if err != nil {
s.Send(err2byte(err))
continue
}
c.Send(cmd)
}
}