我正在运行一个 TCP/IP 套接字,它发送一个 SOAP 消息然后得到一个响应然后读取它。
问题在于这种情况:起初一切都很好,我发送一条消息,然后使用 swingworker 得到响应。如果我关闭套接字并尝试再次连接,我会通过一个布尔值来停止 swing worker。当我再次连接时,我让线程运行,但是当我发送 SOAP 消息时,我没有从套接字获得任何输出,但是当我当时进行调试时,我降级代码,我得到了响应和一个输出!怎么会这样?
这是我的代码:
protected Object doInBackground() throws Exception {
Integer result = 1;
while (true) {
if (startReading && !this.server.isSocketClosed()) {
// send the SOAP Message based on which message is selected
SendSOAPRequestMessage();
//Thread.sleep(5);
String responseMessage = null;
try {
// get the response from the client/server
responseMessage = Utils.convertStreamToString(this.server);
System.out.println(responseMessage);
// give the message without the header + and check the content length and if the header is corrupted
fullMsg = decoder.DecodeSoapHeader(new String(responseMessage.getBytes("UTF-8")));
} catch (Exception ex) {
Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}