V
V
Vladimir Grabko2016-04-24 21:14:22
go
Vladimir Grabko, 2016-04-24 21:14:22

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

1 answer(s)
F
fastpars, 2016-04-24
@lucifer-m

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 question

Ask a Question

731 491 924 answers to any question