summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/client.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/client.go b/internal/client.go
new file mode 100644
index 0000000..164a29d
--- /dev/null
+++ b/internal/client.go
@@ -0,0 +1,31 @@
+package ircd
+
+import (
+ "fmt"
+ "log"
+ "net"
+)
+
+func HandleClientConnection(conn net.Conn) {
+ defer conn.Close()
+ log.Printf("New client connected from %s\n", conn.RemoteAddr())
+
+ buffer := make([]byte, 512)
+
+ for {
+ n, err := conn.Read(buffer)
+ if err != nil {
+ log.Printf("Error reading from client %s: %v\n", conn.RemoteAddr(), err)
+ return
+ }
+
+ data := string(buffer[:n])
+ fmt.Printf("%s sent %s\n", conn.RemoteAddr(), data)
+
+ _, err = conn.Write([]byte("you said " + data))
+ if err != nil {
+ log.Printf("Error sending to client %s: %v", conn.RemoteAddr(), err)
+ return
+ }
+ }
+}