Servidor.java
package javaapplication48;
import java.net.*;
import java.io.*;
public class Servidor {
public static void main(String[] args) throws IOException {
ServerSocket servidor = new ServerSocket(5656);
Socket sv = servidor.accept();
ObjectInputStream out = new ObjectInputStream(sv.getInputStream());
FileOutputStream file = new
FileOutputStream("C:\\Users\\DeveloperEng\\Documents\\newOrder.xml");
byte[] buf = new byte[4096];
while (true) {
int len = out.read(buf);
if (len == -1) break;
file.write(buf, 0 , len);
}
}
}
Cliente.java
package javaapplication48;
import java.net.*;
import java.io.*;
public class Cliente {
public static void main(String[] args) throws IOException {
Socket cliente = new Socket("127.0.0.1", 5656);
ObjectOutputStream out = new
ObjectOutputStream(cliente.getOutputStream());
FileInputStream file = new
FileInputStream("C:\\Users\\DeveloperEng\\Documents\\order.xml");
byte[] buf = new byte [4096];
while (true) {
int len = file.read(buf);
if (len == -1) break;
out.write(buf, 0, len);
}
}
}
No NetBeans, eu executo primeiro o Servidor.java e depois o Cliente.java. Mas ele gera o seguinte erro:
Exception in thread "main" java.net.BindException: Address already in use: JVM_Bind at java.net.DualStackPlainSocketImpl.bind0(Native Method) at java.net.DualStackPlainSocketImpl.socketBind(DualStackPlainSocketImpl.java:106) at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387) at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:190) at java.net.ServerSocket.bind(ServerSocket.java:375) at java.net.ServerSocket.(ServerSocket.java:237) at java.net.ServerSocket.(ServerSocket.java:128) at javaapplication48.Servidor.main(Servidor.java:9) C:\Users\DeveloperEng\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53:
Java returned: 1 FALHA NA CONSTRUÇÃO (tempo total: 0 segundos)
Se alguém souber dizer porque ele gera essa falha e, se possível, me ajudar a corrigir código, eu seria muito grato!!