检查 Java 中本地 TCP 端口是否打开
有没有一种简单的方法来确保本地端口尚未打开。某些 TCP 套接字服务器(例如 Grizzly)默认情况下似乎不执行此检查。如果缺少此检查,服务器似乎会启动并响应,但客户端代码只是连接到未关闭的旧服务器。这可能非常糟糕!
是否有一行简单的 Java 代码可以检查以确保端口尚未被其他进程使用?
Is there a simple way to make sure that a local port is not already open. Some TCP socket servers (eg Grizzly) don't seem to do this check by default. When this check is missing, the server appears to start and respond, but the client code is just connecting to an old server that wasn't shutdown. This can be very bad!
Is there a simple line of Java code that could check to be sure that port isn't already used by another process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看到两种明显的方法:
希望它有帮助。
I see two obvious ways to do it:
Hope it helps.