2013-03-14 14 views
5

Bağlantıları dinleyen bir ServerSocket örneğim var. Bir istemci ona bağlandığında, bağlı soketin IP'sini almak istiyorum, ancak bunu yapmak için doğru yöntemi bulamıyorum.SunucuSocket + client Soket - istemcinin IP adresini nasıl alabilirim?

public void start() { 
    listenSocket = new ServerSocket(port); 
    connectionSocket = listenSocket.accept(); 
} 

hiçbir şans ile aşağıdaki arama çalıştı ettik: Yukarıdaki getiri doğru IP ait

connectionSocket.getLocalAddress(); 
connectionSocket.getInetAddress.getHostAddress(); 
listenSocket.getLocalSocketAddress(); 

Yok. Ya "/ 0: 0: 0: 0: 0: 0: 0: 1% 0" veya "0.0.0.0" döndürürler.

Neyi yanlış yapıyorum?

+1

Yerel adresiniz sonlandırılmıştır. Uzak adresi, diğer ucunu istiyorsun. – EJP

cevap

13
connectionSocket.getRemoteSocketAddress(); 
İlgili konular