how to know which port my Application is using [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
开发者_JAVA技巧 Improve this questionHow can I know on which port my application is running?
That's not a lot of information to go on, but if your app is a general purpose TCP server and you're really not sure whether it's running or not, or on what port, try:
netstat -an -p tcp
(This is a UNIX/Linux/OS X command... not sure what the Windows equivalent is but it will be similar)
This will show you all listening sockets on your machine and the IP address/port on which they are listening. One of them may be your app.
What port did you tell it to run on?
(You're going to have to give us more details about exactly what you/your program are/is doing for us to be able to give you a more helpful answer than the above.)
If your app is a server, and you need to test if it's listening, you can use
netstat -ltpn
The meaning of the switches:
- -l for "listening", that is, server sockets only
- -t for "tcp only"; note that you may need udp, then use -u
- -p for "program": show which process opened which socket
- -n for "numeric": IPs are OK, don't spend time on looking up hostnames
Run it as root (e.g. with sudo) to get process info on sockets opened by the root's processes.
This is for UNIX/Linux. Please specify the system you're using to get more precise answers.
There is a nice util at SysInternals called TCPView.exe
http://live.sysinternals.com/Tcpview.exe
That shows all connections and process IDs
if you're using tcp\ip or udp fport should fit your needs link text
Inside a Servlet you can ask the HttpRequest object how it was invoked including the port and hostname. There is no standard API for a servlet interrogating the container.
精彩评论