Very slow socket execution
I am getting very slow socket initialization. Here is sample code to clarify the issue. I suspect is has to do with reverse lookups or some such thing - is there a way to disable all of that? I tried using the security manager but that is a bad solution because it does not seem doable from within the program - which means it will be slow for users even if I can make it fast for a developer.
public String ExchangeStringWithNet(String Host, Integer Port, String Content) // Send Content to Host on Port - Get back response (send a string - get a string - deal done)
{PrintWriter out;BufferedReader in;Socket socket;
int SleepTime=100;
try {
InetAddress zz = InetAddress.getByName("74.95.10.172");System.out.println("set " + zz);
zz = InetAddress.getByName("all.net");System.out.println("set " + "all.net " + zz);
socket = new Socket(zz, Port);System.out.println("Go");socket.close();
socket = new Socket(zz, Port);System.out.println("Go2");socket.close();
socket = new Socket(zz, Port);System.out.println("Go3");
socket.setSoTimeout(SleepTime);
out = new PrintWriter(socket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));}
catch (UnknownHostException e) {JOptionPane.showMessageDialog(p, "Unknown host: " + Host + ":" + Port + " - Try again later");return("");}
catch (IOException e) {JOptionPane.showMessageDialog(p, "No I/O available with host " + Host + ":" + Port);return("");}
out.println(Content);
String result="";
while (true)
try{line = in.readLine();if (line == null) {System.out.print(".");try{in.close();out.close();socket.close();}
catch (IOException f) {}; return(result);} else result = result + line + "\n";}
catch (IOException e) {JOptionPane.showMessageDialog(p, "Read failed in exchange with " + Host + ":" + Port + " - Please retry later");
try{in.close();out.close();socket.close();} catch (IOException f) {};return(result);}
}

