使用java應用程序在linux中打開端口 (Open port in linux with java application)


問題描述

使用java應用程序在linux中打開端口 (Open port in linux with java application)

I've a java application that creates a socketserver in a port. I test my application in a windows machine, and runs correctly, but when I test it in a linux machine, the port is not listening.

Is there any way to open a port specifically in a linux machine?

I run 'netstat' command, and the port I use in my application doesn't appear. It doesn't throw any exception. I'm trying to connect from another machine to the application, and the connection is refused.

Sincerely, I don't know why it doesn't run...

help please.

thanks, david


參考解法

方法 1:

What is the port number you're trying to open ?

If it's below 1024, then only the root user can open it or grant access to it.

方法 2:

Are you sure your code is actually being executed?  Your comment about the code being in a .sar file implies that you aren't executing it directly, but are deploying it to jboss.  Maybe it is not deployed correctly?  Have you tried putting some logging statements (or even System.out.println statements) before and after the ServerSocket is created?

方法 3:

There should be no difference on Windows and Linux. Can you post an exception-stacktrace, that you most likely get?

The possibilities that are likely are, that your chosen port is already occupied (on Linux usually some services are running) or that you try to bind a port below 1024, that is only allowed for root.

方法 4:

It should work the same. Does it throw an exception on linux? Maybe the target port is occupied already.

Edit: Maybe your code successfully binds to the port but the Linux firewall blocks the incoming connections?

Edit 2: Maybe your Linux JBoss configuration differs and your code which contains the initialization for the ServerSocket is not automatically executed.

方法 5:

use netstat -napt to check (I don't know which arguments you used).

(by DavidJohan BuretJason DayMnementhakarnokdAif)

參考文件

  1. Open port in linux with java application (CC BY-SA 3.0/4.0)

#java #port #linux






相關問題

電子郵件地址中帶有 + 字符的 Java 郵件 (Java mail with + character in email address)

如何快速原型化 Java 代碼? (How to quickly prototype Java code?)

如何使用 Maven 在目標(SVN-)服務器上創建 Javadoc? (How to create Javadoc on the target (SVN-) server using Maven?)

為什麼檢查二叉樹有效性的解決方案不起作用? (Why the solution for checking the validity of binary tree is not working?)

Selenium webdriver通過第一個數字找到texy (Selenium webdriver find texy by first digits)

setOnClickListener 沒有在圖像視圖上被調用 (setOnClickListener is not getting called on image view)

繪製多邊形:找不到錯誤 (Drawing Polygon : unable to find error)

半透明 JButton:對像出現在背景中 (Semi-Transparent JButton: Objects appear in Background)

比較同一數組的元素 (Compare elements of the same array)

Java 屏幕截圖小程序 (Java screen capture applet)

Minecraft 1.8.9 Forge Modding 的Java 開發工具包,需要什麼JDK/JRE,代碼是否正確? (Java Development Kit with Minecraft 1.8.9 Forge Modding, What JDK/JRE Is Needed, Is Code Correct?)

java while (resultset.next()) 不返回同一列中的所有數據 (java while (resultset.next()) does not return all data in the same column)







留言討論