import ( "net" ) func main() { listener, _ := net.Listen("tcp", ":8080") addr := listener.Addr().String() fmt.Println("Listening on", addr) }
import ( "net" ) func main() { listener, _ := net.Listen("tcp", ":8080") for { conn, _ := listener.Accept() addr := conn.RemoteAddr().String() fmt.Println("Connected from", addr) } }In this example, we create a TCP listener on port 8080 and accept incoming connections. For each incoming connection, we print out the remote address from which the connection was made. Package Library: net