I am following the UDP tutorials at http://docs.oracle.com/javase/tutorial/networking/datagrams/broadcasting.html ,I have copied all the code and compiled it, now If I compile the client first and then the server, the server prints this out in console
Exception in thread "main" java.net.BindException: Address already in use: Cannot bind
at java.net.PlainDatagramSocketImpl.bind0(Native Method)
at java.net.PlainDatagramSocketImpl.bind(Unknown Source)
at java.net.DatagramSocket.bind(Unknown Source)
at java.net.DatagramSocket.<init>(Unknown Source)
at java.net.DatagramSocket.<init>(Unknown Source)
at java.net.DatagramSocket.<init>(Unknown Source)
at QuoteServerThread.<init>(QuoteServerThread.java:19)
at MulticastServerThread.<init>(MulticastServerThread.java:10)
at MulticastServer.main(MulticastServer.java:3)
QuoteServerThread line 19 is
socket = new DatagramSocket(12345);
MulticastServerThread line 10 is
public MulticastServerThread() throws IOException {
super("MulticastServerThread"); // line 10
}
MulticastServer line 3 is
public class MulticastServer {
public static void main(String[] args) throws java.io.IOException {
new MulticastServerThread().start(); // line 3
}
}
If I start the server first, then the client, the client prints out this in console
Exception in thread "main" java.net.BindException: Address already in use: Cannot bind
at java.net.PlainDatagramSocketImpl.bind0(Native Method)
at java.net.PlainDatagramSocketImpl.bind(Unknown Source)
at java.net.DatagramSocket.bind(Unknown Source)
at java.net.MulticastSocket.<init>(Unknown Source)
at java.net.MulticastSocket.<init>(Unknown Source)
at MulticastClient.main(MulticastClient.java:9)
MulticastClient line 9 is
MulticastSocket socket = new MulticastSocket(12345);
Looking at the errors, it seems to me that it is something to do with listening to ports, how can I go about fixing this?
Canvas