I opened port #5955 from a java class to comunicate from a client. How do i close this port after I am done? and also which command can show me if port open or closed?
相关问题
- Xcode debugger displays incorrect values for varia
- Is there a way to report errors in Apple documenta
- Advice for supporting both Mac and Windows Desktop
- Avoid cmake to add the flags -search_paths_first a
- Port of the Rails app when running Cucumber tests
相关文章
- 现在使用swift开发ios应用好还是swift?
- Visual Studio Code, MAC OS X, OmniSharp server is
- xcode 4 garbage collection removed?
- IntelliJ IDEA can't open projects or add SDK o
- Automator: How do I use the Choose from List actio
- ImportError: No module named twisted.persisted.sty
- How can I vertically align my status bar item text
- git command-line on Mac OS error “dyld: Symbol not
In 2018 here is what worked for me using MacOS HighSierra:
sudo lsof -nPi :yourPortNumber
then:
sudo kill -9 yourPIDnumber
However you opened the port, you close it in the same way. For example, if you created a socket, bound it to port 0.0.0.0:5955, and called listen, close that same socket.
You can also just kill the process that has the port open.
If you want to find out what process has a port open, try this:
If you want to know whether a port is open, you can do the same lsof command (if any process has it open, it's open; otherwise, it's not), or you can just try to connect to it, e.g.:
If it returns immediately with no output, the port isn't open.
It may be worth mentioning that, technically speaking, it's not a port that's open, but a host:port combination. For example, if you're plugged into a LAN as 10.0.1.2, you could bind a socket to 127.0.0.1:5955, or 10.0.1.2:5955, without either one affecting the other, or you could bind to 0.0.0.0:5955 to handle both at once. You can see all of your computer's IPv4 and IPv6 addresses with the
ifconfig
command.very simple find port 5900:
then considering 59553 as PID
I have created a function for this purpose.
Copy & pasting this block of code in your terminal should free your desired port. Just remember to change the port number in last line.
I use
lsof
combined withkill
, as mentioned above; but wrote a quick little bash script to automate this process.With this script, you can simply type
killport 3000
from anywhere, and it will kill all processes running on port3000
.https://github.com/xtrasimplicity/killport