Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have some code I'm testing. Program A listens on a predefined socket for program B to connect to and for my testing I'm running 32 instances of the programs A and B. I've written my script to tell program A to listen to port 9001-9032 and put in the configuration files for each instance of program B the corrosponding port to connect to.

When I run the script which starts up program A and B and run Netstat -tnap I find that of all the ports 9001-9032 the only port actually used is 9001 which is used by another program (my bad lol). When I grep for program A I find each instance is listening on a semingly completely random ports that have no relationship to the ports 90** they should be listening on. However, my program B, which should be connecting to ports 9001-9032, is able to find and connect to each instance of program A despite A aparntly not listening on the ports it's B should be trying to connect to. I'm rather confused as to how that's possible.

If that isn't confusing enough my 32 program and only the 32 one (listening on 9032) dies at startup with an error that the address was refused when it tries to bind to the port. I tried changing the programs to listen on ports 15001-15032 just to see what would happen and I still got the exact same behavior; all programs seem to be listening on random ports and the 32 program can't establish a connection.

Can anyone explain why my ports are behaving the way the are? Am I misunderstanding some part of netstat or linux ports?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

I recommend to simulate the allegedly broken connections with socat (a command line tool that establish arbitrary byte streams).

Try to listen on the ports with

socat - TCP-Listen:9001

for a tcp connection that listens on port 9001 or

socat - UDP-Listen:9001

for a udp connection.

Examine if netstat -p (or alternatively sockstat) shows the connection that socat established. If so, you should investigate your code further and maybe post a source code related question on stackoverflow.com.

In the other case, please let us know!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.