I have a requirement that requires the rpc server to get the client’s **real IP** and current connection `net.Conn`.
The reason for needing **real IP** and `net.Conn` is roughly for **two-way communication**. I hope to be able to send RPC requests to the client of a specific IP to perform certain operations. For example, issue RPC commands to certain Agent services to execute a certain script. I can get the remoteip through the following RemoteAddr method, but this is not necessarily the real IP of the client. ```go // example_server.go type MathService struct{} type Args struct { A, B int } type Reply struct { Result int } func (m *MathService) Multiply(args *Args, reply *Reply) error { reply.Result = args.A * args.B return nil } func main() { // Create an instance of the MathService mathService := new(MathService) // Register MathService for RPC rpc.Register(mathService) // Create a TCP listener listener, err := net.Listen("tcp", "0.0.0.0:1234") if err != nil { fmt.Println("Error starting server:", err) return } defer listener.Close() fmt.Println("Server listening on :1234") for { // Accept incoming connections conn, err := listener.Accept() if err != nil { fmt.Println("Error accepting connection:", err) continue } fmt.Printf("remote ip addr: %s\n", conn.RemoteAddr().String()) // Serve the connection in a new goroutine go rpc.ServeConn(conn) } } // example_client.go type Args struct { A, B int } type Reply struct { Result int } func main() { // Connect to the server client, err := rpc.Dial("tcp", "127.0.0.1:1234") if err != nil { fmt.Println("Error connecting to server:", err) return } defer client.Close() // Prepare the arguments for the RPC call args := &Args{A: 5, B: 3} // Call the Multiply method remotely var reply Reply err = client.Call("MathService.Multiply", args, &reply) if err != nil { fmt.Println("Error calling Multiply:", err) return } // Print the result fmt.Printf("Result: %d\n", reply.Result) } ``` Therefore, I hope to manually call the`ReportRealIP` function to report the **real IP**, but I cannot get the **current** connected `net.Conn` in the **rpc function**. But I searched some information and found no way to achieve my needs. Is there a way to get the two variables I want? Looking forward to your reply -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b839a250-70e0-4a9a-bdb4-f236030134ccn%40googlegroups.com.