Variable calling not working.  please help

Hi there,
I am trying to include a nslookup utility I have, to run with my messenger server proxy below.
The idea is, is that the address lookup found is saved to a string, which is called dottedQuad, and then using string variable name, I just put that in the consturctor of the socket below.
No matter what I try, I cannot get access to that variable from the try/catch block where that socket declaration is????? please help!!
cheers
// MultiThreadsServer.java: The server can communicate with
// multiple clients concurrently using the multiple threads
import java.io.*;
import java.net.*;
public class MultiThreadServerRead
     String result;
     MultiThreadServerRead server;
// Main method
public static void main(String[] args)
          try
                    System.out.println("Messenger Server proxy");
                    System.out.println("Please enter the PC name of the user you wish to talk to:");
               BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
               String host = in.readLine();
               System.out.println(lookup(host));
     catch (IOException ex){
          System.err.println(ex);
try
     // Create a server socket
ServerSocket serverSocket = new ServerSocket(8000);
// To number a client
int clientNo = 1;
while (true)
// Listen for a new connection request
Socket connectToClient = serverSocket.accept();
// Print the new connect number on the console
System.out.println("Start thread for client " + clientNo);
// Find the client's hostname, and IP address
InetAddress clientInetAddress = connectToClient.getInetAddress();
System.out.println("Client " + clientNo + "'s hostname is "
+ clientInetAddress.getHostName());
System.out.println("Client " + clientNo + "'s IP Address is "
+ clientInetAddress.getHostAddress());
// Create a new thread for the connection
HandleAClient thread = new HandleAClient(connectToClient, clientNo);
// Start the new thread
thread.start();
// Increment clientNo
clientNo++;
catch(IOException ex)
System.err.println(ex);
} //end catch
}//end main
               public static String lookup(String host )
                    InetAddress thisComputer;
                    byte[] address;
                    //get the bytes of the IP address
                    try
                         thisComputer = InetAddress.getByName(host);
                         address = thisComputer.getAddress();
                    catch
                    (UnknownHostException e)
                         return "Cannot find host " + host;
                    if( isHostName(host))
                         MultiThreadServerRead server = new MultiThreadServerRead();
                         //print the IP address
                         String dottedQuad = "";
                         for (int i = 0 ; i< address.length; i++)
                              int unsignedByte = address[i] < 0 ? address[i] + 256 : address;
                              dottedQuad += unsignedByte;
                              if (i != address.length-1) dottedQuad += ".";
                         server.result = dottedQuad;
                         return dottedQuad;
                    else
                    {     //this is an IP address
                         return thisComputer.getHostName();
               } // end lookup
               public static boolean isHostName(String host)
                    char[] ca = host.toCharArray();
                    //if we see a character that is neither a digit nor a period
                    // then host is proberbly a host name
                    for (int i = 0; i < ca.length; i++)
                         if (!Character.isDigit(ca[i]))
                              if ( ca[i] != '.') return true;
                    //Everything was either a digit or a period
                    //so host looks like an IP address in dotted quad format
                    return false;
               } //end isHostName     
} //end class
// Define the thread class for handling a new connection
class HandleAClient extends Thread
     String timeString ;
private Socket connectToClient; // A connected socket
private int clientNo; // Indicate client no
// Construct a thread
public HandleAClient(Socket socket, int clientNo)
connectToClient = socket;
this.clientNo = clientNo;
// Implement the run() method for the thread
public void run()
try
// Create data input and output streams
     InputStream isFromClient = connectToClient.getInputStream();
     //OutputStreamWriter osToClient = new OutputStreamWriter(connectToClient.getOutputStream());
     StringBuffer time = new StringBuffer();
     int c;
     while ((c = isFromClient.read()) != -1) time.append((char) c);
     timeString = time.toString().trim();
     System.out.println("it is " + timeString + " at " );
catch(IOException ex)
System.err.println(ex);
} //end catch
try
     // Create data input and output streams
          StringBuffer time = new StringBuffer();
               int c;
          Socket connectToServer = new Socket("192.168.0.3", 8001);
          OutputStreamWriter osToServer = new OutputStreamWriter(connectToServer.getOutputStream());
     // Continuously serve the client
     //      while (true)
//               System.out.println(lookup(host));
               osToServer.write("WRITE BACK TO CLIENT " + timeString + "\r\n" );
               osToServer.flush();
               connectToServer.close();
     catch(IOException ex)
     System.err.println(ex);
     } //end catch
} //end run
} // end class

If you want to access a variable from outside of a block, then don't declare it inside the block.

Similar Messages

Maybe you are looking for

  • How to change host name and domain name in installed Cisco Meeting Place Express 2.0?

    Hi I have  Cisco Meeting Place Express 2.0 installed on server. Meting Place uses Linux (Red Hat) as base operation system. Please tell me how I can change host name and domain name for Meeting Place Express application to integrate it into corporate

  • NWDS not showing keywords

    Hi xperts, As you know, when we type in any keyword in NWDS it gets highlighted with different font /color. But in my system, when I type keywords like if, try, catch; it simply disappears. I have reinstalled every thing (right from java) but the pro

  • Knowing and Manipulating Blinking Caret Position inside a cell in Datagrid in AS3?

    Hi, i've made a datagrid and wish to know position of blinking caret within a edited text cell in datagrid in AS3. I know there are some TextField properties available which allow manipulating/highlighting text based on user input. However, i'm unabl

  • Comment on Dynamic PDF

    Hi All, I'm new to Adobe LiveCycle as well as the forum. I've created a PDF form using Adobe LiveCycle ES2 whereby users are able to fill in the details for some calculations. It's an interactive form in the sense that it retrieves data from a Ms Acc

  • Viewing webcams on iPad

    I am trying to view a live webcam on my iPad. The website is saying the webcast usesQuickTime. I thought this was possible on iPad. Any suggestions please.