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!