views:

27

answers:

1

Using netstat i found this in my list

  TCP    127.0.0.1:9832         My-PC:9832          ESTABLISHED

My question is how is my local port outgoing AND CONNECTED to the same TCP port?

This is breaking my code because i am listening to port 9832. I am getting a permission error. I need to lose firefox and reopen all my tabs before this code will work. Another question i guess would be is there a range that should be used for listening and will not be use as an outgoing connection?

I am confused.

A: 

It is perfectly valid to use the same port number for both outgoing connections and listening. If you are connecting to your own computer, then you'll get netstat output like you showed.

A TCP connection is identified by the 4-tuple (source-ip, source-port, dest-ip, dest-port), so there's nothing that says source-port cannot be the same as dest-port.

Perhaps you are binding to a particular port in your client code? Normally you only need to bind to a specific port for the server code.

Your issue about having to close Firefox is undoubtedly unrelated to this.

Greg Hewgill
What not kosher, though, is having the same port at both ends of a *loopback* connection. Then the 4-tuple would be the same in both directions. Also, I don't think it's possible to establish a connection which has a loopback address on one side and a non-loopback on the other.
Ben Voigt
I thought it isnt valid to have a port for out and in especially if the IP Addr is the same. If a packet is sent from 127.0.0.1:123 to 127.0.0.1:123 how does it know if it was sent by the server or client? If i see a packet on the queue to 127.0.0.1:123 how do i know its the client or server receiving. That is so confusing.
acidzombie24
My *client* code is some ajax. GM_xmlhttpRequest to be exact. I dont think it is possible to bind to a port. I have multiple clients with no problems. It just later when i get a problem. Maybe my sockets are still alive after i kill my process in VS. I am still confused.
acidzombie24