mirror of
https://github.com/kataras/iris.git
synced 2025-12-17 18:07:01 +00:00
_examples/websocket/basic: add a nodejs client and provide a README.md on how to run the websocket clients and the server
Former-commit-id: a98a80996d7d95fa947e72c71803407682229fa7
This commit is contained in:
@@ -24,20 +24,15 @@ const (
|
||||
var clientEvents = websocket.Namespaces{
|
||||
namespace: websocket.Events{
|
||||
websocket.OnNamespaceConnected: func(c *websocket.NSConn, msg websocket.Message) error {
|
||||
log.Printf("[%s] connected to namespace [%s]", c, msg.Namespace)
|
||||
log.Printf("connected to namespace: %s", msg.Namespace)
|
||||
return nil
|
||||
},
|
||||
websocket.OnNamespaceDisconnect: func(c *websocket.NSConn, msg websocket.Message) error {
|
||||
log.Printf("[%s] disconnected from namespace [%s]", c, msg.Namespace)
|
||||
log.Printf("disconnected from namespace: %s", msg.Namespace)
|
||||
return nil
|
||||
},
|
||||
"chat": func(c *websocket.NSConn, msg websocket.Message) error {
|
||||
log.Printf("[%s] sent: %s", c.Conn.ID(), string(msg.Body))
|
||||
|
||||
// Write message back to the client message owner with:
|
||||
// c.Emit("chat", msg)
|
||||
// Write message to all except this client with:
|
||||
c.Conn.Server().Broadcast(c, msg)
|
||||
log.Printf("%s", string(msg.Body))
|
||||
return nil
|
||||
},
|
||||
},
|
||||
@@ -58,6 +53,8 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
c.Emit("chat", []byte("Hello from Go client side!"))
|
||||
|
||||
fmt.Fprint(os.Stdout, ">> ")
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
for {
|
||||
|
||||
Reference in New Issue
Block a user