0

I have an application that is running and listening for local requests on port 4001. Whenever I start a second application to place requests through port 4001 my mac appears to be automatically forwarding the request to a different port. For example, when I check t see what processes are running on port 4001 prior to launching the second application I get:

Grants-MacBook-Pro:sbin grantseward$ sudo lsof -i -n -P | grep 4001
Password:
java        113    grantseward   52u  IPv6 0x3465d3725017ec8d      0t0  TCP *:4001 (LISTEN)

But as soon as I launch the second app it appears to originally send requests to port 4001 but then they get routed to 49509 and that port is closed / not what my other app is listening to (the second port also changes each time I stop and start the second app so I can't simply change where I am listening).

Grants-MacBook-Pro:sbin grantseward$ sudo lsof -i -n -P | grep 4001
java        113    grantseward   52u  IPv6 0x3465d3725017ec8d      0t0  TCP *:4001 (LISTEN)
java        113    grantseward   59u  IPv6 0x3465d3725f0a988d      0t0  TCP 127.0.0.1:4001->127.0.0.1:49505 (CLOSE_WAIT)
java        121    grantseward   80u  IPv6 0x3465d3726032d38d      0t0  TCP 127.0.0.1:49506->127.0.0.1:4001 (ESTABLISHED)

Any ideas how I can change the rules to have requests sent to 4001 end up at 4001?

1 Answer 1

0

What you're seeing is normal; it's not that the connection is being forwarded to port 49505, it's that a client program running on port 49505 is connecting to the service on port 4001. A TCP session is defined by the IP address and port numbers of the two ends of the connection; in this case you have a session between 127.0.0.1:4001 (process ID 113, the server program) and 127.0.0.1:49505 (process ID 121, the client program).

BTW, every time you re-run the client (or the client opens a new connection), it'll generally be assigned a new source port (instead of 49505).

1
  • Thanks, this indirectly helped me find the root cause.. It turns out there was a socket being opened that was never closed which prevented me from making the connection I wanted.
    – user416988
    Commented Feb 10, 2015 at 2:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .