From d810d12355873d3eaf61ed3f7f0ae52db06c2c96 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 8 Dec 2024 08:45:13 +0800 Subject: Add basic command handling --- client.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 client.go (limited to 'client.go') diff --git a/client.go b/client.go new file mode 100644 index 0000000..9c73444 --- /dev/null +++ b/client.go @@ -0,0 +1,25 @@ +package main + +import ( + "net" +) + +type Client struct { + conn net.Conn + uid [6]byte +} + +func (client *Client) Send(msg SMsg) { + client.SendRaw(msg.ClientSerialize()) +} + +// Send failures are not returned; broken connections detected and severed on +// the next receive. +func (client *Client) SendRaw(s string) { + _, err := client.conn.Write([]byte(s)) + if err != nil { + // TODO: Should shut down the netFd instead but the stdlib + // doesn't expose a way to do this. + client.conn.Close() + } +} -- cgit v1.2.3