package main import ( "fmt" "net" ) func main() { ln, err := net.Listen("tcp", ":8080") if err != nil { fmt.Println(err) return } defer ln.Close() fmt.Println("Listening on port 8080...") for { conn, err := ln.Accept() if err != nil { fmt.Println(err) continue } go handleConnection(conn) } } func handleConnection(conn net.Conn) { defer conn.Close() // handle incoming data }
package main import ( "fmt" "net" ) func main() { ln, err := net.Listen("unix", "/tmp/server.sock") if err != nil { fmt.Println(err) return } defer ln.Close() fmt.Println("Listening on Unix socket /tmp/server.sock...") for { conn, err := ln.Accept() if err != nil { fmt.Println(err) continue } go handleConnection(conn) } } func handleConnection(conn net.Conn) { defer conn.Close() // handle incoming data }This example starts a Unix domain socket server and waits for incoming connections. Once a new connection is accepted, a new goroutine is created to handle the incoming data. Both of these examples use the "net" package, which is part of the standard library in Go.