Skip to content

Commit

Permalink
feat(examples): add websocket echo server implementation
Browse files Browse the repository at this point in the history
Implement a basic websocket echo server within the examples directory to
demonstrate how to utilize the minotaur framework for websocket
connections. The server subscribes to connection opened events andreplies with the received packets.
  • Loading branch information
kercylan98 committed Jun 18, 2024
1 parent d542b36 commit 671ed64
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/internal/websocket-each-server/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"github.com/kercylan98/minotaur/minotaur"
"github.com/kercylan98/minotaur/minotaur/transport"
"github.com/kercylan98/minotaur/minotaur/transport/network"
"github.com/kercylan98/minotaur/minotaur/vivid"
)

func main() {
minotaur.NewApplication(
minotaur.WithNetwork(network.WebSocket(":8080")),
).Launch(func(app *minotaur.Application, ctx vivid.MessageContext) {
switch m := ctx.GetMessage().(type) {
case vivid.OnBoot:
app.GetServer().SubscribeConnOpenedEvent(app)
case transport.ServerConnectionOpenedEvent:
m.Conn.SetPacketHandler(func(ctx vivid.MessageContext, conn transport.Conn, packet transport.ConnectionReactPacketMessage) {
conn.Write(packet)
})
}
})
}

0 comments on commit 671ed64

Please sign in to comment.