File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -265,6 +265,18 @@ func (c *Connection) LocalAddr() net.Addr {
265265 return & net.TCPAddr {}
266266}
267267
268+ /*
269+ RemoteAddr returns the remote TCP peer address, if known.
270+ */
271+ func (c * Connection ) RemoteAddr () net.Addr {
272+ if conn , ok := c .conn .(interface {
273+ RemoteAddr () net.Addr
274+ }); ok {
275+ return conn .RemoteAddr ()
276+ }
277+ return & net.TCPAddr {}
278+ }
279+
268280// ConnectionState returns basic TLS details of the underlying transport.
269281// Returns a zero value when the underlying connection does not implement
270282// ConnectionState() tls.ConnectionState.
Original file line number Diff line number Diff line change @@ -134,6 +134,28 @@ func TestIntegrationLocalAddr(t *testing.T) {
134134 t .Logf ("Connected to port %d\n " , port )
135135}
136136
137+ func TestIntegrationRemoteAddr (t * testing.T ) {
138+ config := Config {}
139+
140+ c , err := DialConfig (amqpURL , config )
141+ if err != nil {
142+ t .Fatalf ("expected to dial with config %+v integration server: %s" , config , err )
143+ }
144+ defer c .Close ()
145+
146+ a := c .RemoteAddr ()
147+ _ , portString , err := net .SplitHostPort (a .String ())
148+ if err != nil {
149+ t .Fatalf ("expected to get a remote network address with config %+v integration server: %s" , config , a .String ())
150+ }
151+
152+ port , err := strconv .Atoi (portString )
153+ if err != nil {
154+ t .Fatalf ("expected to get a TCP port number with config %+v integration server: %s" , config , err )
155+ }
156+ t .Logf ("Connected to port %d\n " , port )
157+ }
158+
137159// https://github.com/streadway/amqp/issues/94
138160func TestExchangePassiveOnMissingExchangeShouldError (t * testing.T ) {
139161 c := integrationConnection (t , "exch" )
You can’t perform that action at this time.
0 commit comments