"Exception in thread "main" java.net.BindException: Address already in use: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)"
By the way, i checked for any process using the same port in the command window by typing "netstat -a" and i didn't find any.
The server code:
Expand|Select|Wrap|Line Numbers
- try {
- ServerSocket server = new ServerSocket(8221);
- System.out.println("Waiting for clients\n");
- Socket connection = server.accept();
- ObjectInputStream input = new ObjectInputStream(connection.getInputStream());
- ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream());
- StringBuffer buff = new StringBuffer();
- do {
- int c = 0;
- while (((c = input.read()) != '\n') || ((c = input.read()) != -1)) {
- buff.append(c);
- }
- msg = buff.toString();
- } while (msg != "Exit");
- System.out.println(msg);
- } catch (IOException ex) {
- Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
- }
Expand|Select|Wrap|Line Numbers
- try {
- Socket client = new Socket(InetAddress.getLocalHost(),8221);
- //Socket client = new Socket("192.168.1.18",8221);
- ObjectInputStream input = new ObjectInputStream(client.getInputStream());
- ObjectOutputStream output = new ObjectOutputStream(client.getOutputStream());
- String msg = "Hello Exit";
- output.writeBytes(msg);
- // StringBuffer buff = new StringBuffer();
- // do {
- // int c = 0;
- // while (((c = input.read()) != '\n') || ((c = input.read()) != -1)) {
- // buff.append(c);
- // }
- // msg = buff.toString();
- // } while (msg != "Exit");
- } catch (IOException ex) {
- // Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
- System.out.println(ex);
- }