我的大学工作应用程序..
文档转PDF
==
我的服务器:
每个申请一个线程
server = new ServerSocket(5000);
while (true) {
Socket cliente = server.accept();
Thread thread = new Thread(new Requisitor(cliente));
thread.start();
}
我的班级申请者(运行方法)
@Override
public void run() {
// receive doc binary
receive();
// doc to pdf
Conversor converson = new Conversor(new File("docs/"+cliente.getInetAddress().getHostAddress()+".doc"),new File("pdfs/"+cliente.getInetAddress().getHostAddress()+".pdf"));
converson.converter();
//response pdf binary to client
response();
}
但是没有调用方法receive()..只有当我断开客户端套接字时。
我的客户端套接字:
Client cliente = new Client();
cliente.connect();
cliente.send(); // send doc binary
boolean flag = true;
while (flag) {
if(!cliente.streamIsEmpty()){ // wait for conversion
cliente.receive(); // receive pdf
flag = false;
}
}
cliente.disconect()
我的接收方法
InputStream in = cliente.getInputStream();
BufferedInputStream stream = new BufferedInputStream(in);
FileOutputStream out = new FileOutputStream("docs/"+cliente.getInetAddress().getHostAddress()+".doc");
byte[] buffer = new byte[1024];
int length = 0;
while((length = stream.read(buffer, 0, 1024)) != -1) {
out.write(buffer, 0, length);
}
out.flush();
stream.close();
任何的想法?:(