Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个从 TCPListener.acceptTCP 接受的 TCPConn*。我只想将 IP 地址(无端口信息)作为字符串或 IP 获取。什么是正确的(即最小的转换/字符串操作)方法来实现这一点?
获取IP,作为IP对象,最直接的方式应该是
tcpconn.RemoteAddr().(*net.TCPAddr).IP
使用类型断言并没有错,在这种情况下,它实际上是预期的。