It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center




已关闭8年。




所以..我有一个服务器套接字,在这里:
ServerSocket server = new ServerSocket(5000);

while(true){
    Socket cliente = server.accept();
    Thread thread = new Thread(new Converter(cliente));
    thread.start();

我的应用程序将Word文档(.doc)转换为PDF。首先,我的服务器在收到.pdf归档文件的响应后,接收到一个.doc文件,进行了转换。

如何获得正在等待响应的客户端?

最佳答案

如果我对您的理解正确,那么您正在为每个接受的套接字(因此客户端)创建一个线程。此Converter线程可以访问客户端套接字(每个客户端的accept()返回的套接字都不同)。现在解决方案非常简单:

public void run() {
    cliente.getInputStream();  //read .doc first
    //do the conversion to .pdf
    cliente.getOutputStream();  //send .pdf back
}

关于java - mySocketClient.waitingForResponse()还是类似的? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13128243/

10-12 04:28