hprose / hprose-golang

Hprose is a cross-language RPC. This project is Hprose for Golang.
MIT License
1.26k stars 205 forks source link

获取客户端ip #84

Closed ideamean closed 5 years ago

ideamean commented 5 years ago

package main

import ( "github.com/hprose/hprose-golang/rpc" )

func hello(name string) string { //在这里获取客户端的ip return "Hello " + name + "!" }

func main() { server := rpc.NewTCPServer("tcp4://0.0.0.0:4321/") server.AddFunction("hello", hello) server.Start() }

在这个示例中,如何获取客户端的ip呢?

andot commented 5 years ago
func hello(name string, context *rpc.SocketContext) string {
    return context.Conn.RemoteAddr().String() + " Hello " + name + "!"
}