From fc50027b3952f745942ca11e236760f3c49a21ad Mon Sep 17 00:00:00 2001 From: raul Date: Mon, 11 Mar 2024 08:43:14 +0100 Subject: [PATCH] Preparing all basic files --- client.go | 5 +++++ go.mod | 3 +++ main.go | 9 +++++++++ server.go | 24 ++++++++++++++++++++++++ tools.go | 16 ++++++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 client.go create mode 100644 go.mod create mode 100644 main.go create mode 100644 server.go create mode 100644 tools.go diff --git a/client.go b/client.go new file mode 100644 index 0000000..542a1dd --- /dev/null +++ b/client.go @@ -0,0 +1,5 @@ +package main + +func client() { + +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b9dea94 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module battleship + +go 1.22.1 diff --git a/main.go b/main.go new file mode 100644 index 0000000..aab7c20 --- /dev/null +++ b/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("Sample text") +} diff --git a/server.go b/server.go new file mode 100644 index 0000000..7cf4ab4 --- /dev/null +++ b/server.go @@ -0,0 +1,24 @@ +package main + +import ( + "fmt" + "net" +) + +func server() { + +} + +func getIP(conn net.Conn) (address *net.TCPAddr) { + if addr, ok := conn.RemoteAddr().(*net.TCPAddr); ok { + return addr + //fmt.Printf("Received connection from: %v\n", addr) + } + return +} + +func handleConn(conn net.Conn) { + fmt.Println() + address := getIP(conn) + fmt.Printf("%v connected!\n", address) +} diff --git a/tools.go b/tools.go new file mode 100644 index 0000000..b99c7c4 --- /dev/null +++ b/tools.go @@ -0,0 +1,16 @@ +package main + +import ( + "fmt" + "os" +) + +func catchErr(err error) (errHappened bool) { + errHappened = false + if err != nil { + errHappened = true + fmt.Println(err) + os.Exit(2) + } + return errHappened +}