[英]How to use Java to listen to port 17, 'qotd'?
問題是我只找到有關端口17的一些描述,也稱為“日期行情”端口。 無用的端口,除了顯示少於512個ASCII字符的引號外,什么也不做。 有人可以給我更多有關如何在Java中監聽端口17的信息嗎? 我已經使用端口6017建立了服務器客戶端套接字。
這是代碼:
public class DateServer {
public static void main(String[] args) {
try {
ServerSocket sock = new ServerSocket(6017);
// now listen for connections
while (true) {
Socket client = sock.accept();
// we have a connection
PrintWriter pout = new PrintWriter(client.getOutputStream(), true);
// write the Date to the socket
pout.println(); // I know something must happens here!!!
// close the socket and resume listening for more connections
client.close();
}
} catch (IOException ioe) {
System.err.println(ioe);
}
}
}
系統在Linux上運行,此代碼是程序的服務器端。 我正在客戶端部分上工作,嘗試使服務器執行與端口17相同的操作,然后讓客戶端從服務器接收“每日報價”。
小於1024的端口具有特權,並且需要升級的權限才能運行。 在端口設置為17的情況下,以計算機的管理員身份運行程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.