0
我使用套接字在java中創建了多個客戶端 - 服務器通信。我有一臺服務器和一臺客戶機。我想用多個客戶測試我的程序。我打算創建一個動態創建IP和端口的模擬器..爲此,我只想知道如何在套接字程序中設置客戶端IP和端口。任何人都可以幫助我..我使用InetAddress.getByName獲取客戶端地址。如何在java中使用客戶端套接字程序知道客戶端端口和IP地址
public Socket(Proxy proxy)
{
if (proxy != null && proxy.type() == Proxy.Type.SOCKS)
{
SecurityManager security = System.getSecurityManager();
InetSocketAddress epoint = (InetSocketAddress) proxy.address();
if (security != null) {
if (epoint.isUnresolved())
epoint = new InetSocketAddress(epoint.getHostName(), epoint.getPort());
if (epoint.isUnresolved())
security.checkConnect(epoint.getHostName(),
epoint.getPort());
else
security.checkConnect(epoint.getAddress().getHostAddress(),
epoint.getPort());
}
impl = new SocksSocketImpl(proxy);
impl.setSocket(this);
} else {
if (proxy == Proxy.NO_PROXY) {
if (factory == null) {
impl = new PlainSocketImpl();
impl.setSocket(this);
} else
setImpl();
} else
throw new IllegalArgumentException("Invalid Proxy");
}
}
此代碼似乎是從java.net.Socket中。與你的問題的聯繫逃脫了我。你的問題本身就能逃脫我。 – EJP