1
你好我正在製作一個服務器,它將監聽端口6112,並說如果客戶端連接到它,我已經嘗試在兩種語言中執行它..但它偵聽連接並沒有檢測到任何東西..任何幫助?c#TcpClient和java ServerSocket
繼承人例如代碼:
public static ServerSocket Start() throws Exception
{
System.out.println("Initializing Network Listener");
Config.Initialize();
int netport = Config.netport;
String netip=Config.netadress;
ServerSocket Listener = new ServerSocket(netport);
System.out.println("Done initializing Network Listener");
Listener.setSoTimeout(0);
return Listener;
}
public static void ListenForClient() throws Exception
{
ServerSocket Listener = Start();
Listener.setSoTimeout(0);
Socket Client = Listener.accept();
Client.setSoTimeout(120000);
System.out.println("Client Connected on port: ");
}
綁定是通過ServerSocket的構造與詮釋PARAM完成。看到這裏:http://docs.oracle.com/javase/1.4.2/docs/api/java/net/ServerSocket.html#ServerSocket(int) – Fildor
感謝您的答覆...順便說說有沒有辦法讓服務器偵聽代理服務器?有點設置我的服務器的IP讓可以說78,96,32,154 ..感謝 – SteppeHawk
嗨,很高興它幫助。並感謝Fildor的建設性更正 - 絕對讚賞!問:Java聯網API可以使用代理嗎?答:是:http://docs.oracle.com/javase/1.5.0/docs/guide/net/proxies.html。問:Java *可以代理嗎?答:是的:http://www.java2s.com/Code/Java/Network-Protocol/Asimpleproxyserver.htm – paulsm4