func handleConnection(conn *websocket.Conn) { remoteAddr := conn.RemoteAddr().String() fmt.Println("New connection from:", remoteAddr) // further code to handle connection }
func main() { ws, err := websocket.Dial("ws://example.com/ws", "", "http://example.com/") if err != nil { log.Fatal(err) } remoteAddr := ws.RemoteAddr().String() fmt.Println("Connected to:", remoteAddr) // further code to use the WebSocket connection }This code establishes a WebSocket client connection to a server and prints the remote address of the server. Package library: go.net/websocket