Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: InetAddress worn't work :(

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default InetAddress worn't work :(

    Hi,

    I'm doing a project for uni and not sure why this won't work. Still new to java so anything that's really out of whack let me know

    Cheers in advance
    public class Main
    {
     
            static public void main(String[] argv)
    	{
                String read;
                Scanner in = new Scanner(System.in);
                Thread t1;
                System.out.print("Would you like to connect to the cinema? Y/N");
                read = in.nextLine();
                InetAddress adtep;
                adtep = new InetAddress(InetAddress.getByName(argv[0]));
                t1 = new Thread ( new readFromServer (adtep,5000));
     
                if(read == "Y")
                {
                    System.out.print("Connecting to server");
     
                   t1.start();
                }
                if(read == "N"){System.out.print("exiting ");}
                else{System.out.print("Fail");}
                }
     
    class readFromServer implements Runnable
    {
        InetAddress addy;   
        int port;           
        DatagramSocket reSocket;   
        DatagramPacket rePacket;   
        byte[] buffer = new byte[1024];
     
        public readFromServer (InetAddress addy, int port)
        {
            this.addy = addy; //initialize addy
            this.port = port;   //initialize port
     
            try //Try has to be used to initialize these variables
            {
            this.reSocket.setSoTimeout(0); 
            this.reSocket = new DatagramSocket(this.port); 
            this.rePacket = new DatagramPacket(this.buffer,this.buffer.length);
            }
            catch(IOException ie)
            {
            System.out.print("Error: readFromServer.initializingVariables.001"+
                     " Please contact for this error");
                try {Thread.sleep(1000);
                    System.exit(1);}
                catch(InterruptedException iea){}
     
            } 
        }
     
        readFromServer(String string, String string0) {
            throw new UnsupportedOperationException("Not yet implemented");
        }
     
        public void run()
        {
            while(true) //The thread will continuously run to pick up data
            {
     
                //The following statement will wait untill data is recieved
                try{reSocket.receive(rePacket);}
                catch(IOException ie){}
            }
     
     
        }
     
     
     
     
     
    }
    Last edited by copeg; March 27th, 2011 at 09:47 AM.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: InetAddress worn't work :(

    For future reference, please use the code tags (see my signature for instructions). What about this 'won't work'? Does it compile? Throw exceptions (what are they)? Behave incorrectly (what do you expect and what do you get)? Be as detailed as possible

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: InetAddress worn't work :(

    Ahhh this is a bit embarrasing! I got it sorted. long story

    Thanks though

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: InetAddress worn't work :(

    Please do share...might help someone with the same problem who finds this post in the future.

Similar Threads

  1. MergeSort won't work
    By joshft91 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 7th, 2011, 09:44 PM
  2. How do get and set methods work??
    By merdzins in forum Object Oriented Programming
    Replies: 2
    Last Post: December 25th, 2010, 03:17 AM
  3. home work ..
    By shane1987 in forum Collections and Generics
    Replies: 8
    Last Post: November 16th, 2010, 09:45 AM
  4. My lines won't work!!!
    By The Mewzytion in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 2nd, 2010, 10:24 AM
  5. Why won't this while loop work?
    By trueblue in forum Loops & Control Statements
    Replies: 2
    Last Post: July 17th, 2009, 09:10 AM

Tags for this Thread