package main import ( "bufio" "fmt" "net" "strconv" "strings" ) func server() { ln, err := net.Listen("tcp", ":1302") fmt.Printf("Listening on port 1302...\n") catchErr(err) for { conn, err := ln.Accept() catchErr(err) go handleConn(conn) } } 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) //go game() for { gameStatus() conn.Write([]byte(gameStatus())) conn.Write([]byte("X: ")) x, err := bufio.NewReader(conn).ReadString('\n') catchErr(err) conn.Write([]byte("Y: ")) y, err := bufio.NewReader(conn).ReadString('\n') x = strings.TrimRight(x, "\n") y = strings.TrimRight(y, "\n") catchErr(err) xint, err := strconv.Atoi(x) catchErr(err) yint, err := strconv.Atoi(y) catchErr(err) xint-- yint-- //checkShip(xint, yint) } }