Skip to content

Commit 7349f4f

Browse files
committed
Very basic websocket setup, please ignore
1 parent 19fd3ce commit 7349f4f

File tree

3 files changed

+35
-341
lines changed

3 files changed

+35
-341
lines changed

ebiten-game/game/main.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,22 +305,26 @@ func (g *game) openWebsocket() {
305305
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
306306
defer cancel()
307307

308-
c, _, err := websocket.Dial(ctx, fmt.Sprintf("ws://%s:%d/lobbies", g.signalingIP, g.port), nil)
308+
c, _, err := websocket.Dial(ctx, fmt.Sprintf("ws://%s:%d/host", g.signalingIP, g.port), nil)
309309
if err != nil {
310310
println("Failed to connect to websocket:", err.Error())
311311
}
312312
defer c.CloseNow()
313313

314-
err = wsjson.Write(ctx, c, "open websocket")
315-
if err != nil {
316-
println("Failed to write websocket message:", err.Error())
314+
ticker := time.NewTicker(1 * time.Second)
315+
defer ticker.Stop()
316+
317+
for range ticker.C {
318+
err = wsjson.Write(ctx, c, fmt.Sprintf("ping from client at %s", time.Now().String()))
319+
if err != nil {
320+
println("Failed to write websocket message:", err.Error())
321+
}
317322
}
318323

319324
c.Close(websocket.StatusNormalClosure, "")
320325
}
321326

322327
func (g *game) startHost() {
323-
g.openWebsocket()
324328
g.writeLog("Hosting a lobby")
325329
// Host creates lobby.
326330
req, err := http.NewRequestWithContext(context.Background(), "GET", g.getSignalingURL()+"/lobby/host", nil)

ebiten-game/game/ui.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (g *game) logWindow(ctx *debugui.Context) {
3232
ctx.GridCell(func(bounds image.Rectangle) {
3333
submitOpen := func() {
3434
g.isHost = true
35-
g.startConnection()
35+
g.openWebsocket()
3636
}
3737

3838
submitJoin := func() {

0 commit comments

Comments
 (0)