Reputation: 11
Is there a way to pass a string argument to the parameters of InetSocketAddress
?
this is correct way to generate proxy:
SocketAddress addr = new InetSocketAddress("127.0.0.1", 9050);
Proxy proxy = new Proxy(Proxy.Type.SOCKS, addr);
But I want to create method to take in a string like this:
method("127.0.0.1",9050);
public void method (String a){
SocketAddress addr = new InetSocketAddress(a); //can't place string here is there away forit work?
Proxy proxy = new Proxy(Proxy.Type.SOCKS, addr);
}
Is there any way to get new InetSocketAddress
to take the string IP?
Upvotes: 1
Views: 3181
Reputation: 111369
You have to pass the port to the constructor too, not just the IP address:
method("127.0.0.1",9050);
public void method (String a, int port){
SocketAddress addr = new InetSocketAddress(a, port);
Proxy proxy = new Proxy(Proxy.Type.SOCKS, addr);
}
Upvotes: 4