Skip to main content

Listening on a TCP port Range.

1 reply [Last post]
Joined: 2009-09-25
Points: 0


I am trying to architect a solution to a problem and would like advice on the best way to tackle this. I need to write an application that listens on a range of TCP ports (possibly thousands) for input, When data is received on a port, the application will prepent the port number it was received on to the payload and send it on another socket connection to an application that will process and route the raw data based on the prepended port number.

I am essentially trying to conserve my system by not having thousands of threads running on the server by listening on ports that may rarely be used to receive data.



Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-11-01
Points: 0

I suggest you use firewall software which is designed to do this sort of thing.
On Linux you can use a the built in firewall to do this. I would imagine there is a free firewall for Windows too if you hunt around for it.
Java is not low level enough to prevent another program from getting its packets.
You can look at a JPCAP to snoop packets for a range of ports.
I wouldn't worry about the number of threads, it is the least of your problems. Get something which works first.