2016-12-24 58 views
0

我必須編寫兩個程序:服務器和客戶端 - 在某個端口上運行服務器,同時在該端口上運行客戶端。我在我的計算機上運行所有內容,並將客戶端程序的參數作爲機器地址的本地主機,但出於某種原因,它被視爲jarfile。我有:錯誤:無法訪問jarfile localhost

String hostname = args[0]; 
int port = Integer.parseInt(args[1]); 
... 
Socket socket = new Socket(hostname, port); 
... 

與調用它:

java -jar client.jar localhost 1234 

但我收到以下錯誤:

Error: unable to access jarfile localhost

回答

0

發現了它。我沒有密封整個JAR,只是一些軟件包,所以我的程序沒有將localhost識別爲機器地址。