Answer the question
In order to leave comments, you need to log in
How to find out from which ip the request came from?
I receive a request on the tcp server. How to find out from which ip it was sent? I DID NOT GOOGLE AS I COULD NOT MAKE A REQUEST
Answer the question
In order to leave comments, you need to log in
https://golang.org/pkg/net/#Conn
// RemoteAddr returns the remote network address.
RemoteAddr() Addr
ln, err := net.Listen("tcp", ":8080")
if err != nil {
// handle error
}
for {
conn, err := ln.Accept()
if err != nil {
// handle error
}
fmt.Println(conn.RemoteAddr()) // <---------------
go handleConnection(conn)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question