Hi,
We need to sent and receive data through an socket connection to an external socket server. If we run a java program outside wm we dont have any problems open the connection, send and receive data. But when we implement the code below in a Java Service inside wm the application hang until the connection times out. Any ideas on how to solve the problem ?
Thanks
Örjan
Code:
// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String host = IDataUtil.getString(pipelineCursor, “host”);
String port = IDataUtil.getString(pipelineCursor, “port”);
String data = IDataUtil.getString(pipelineCursor, “data”);
String responseEndTag = IDataUtil.getString(pipelineCursor, “responseEndTag”);
pipelineCursor.destroy();
StringBuffer xml = new StringBuffer(“”);
try {
InetAddress inetAddress = InetAddress.getByName(host);
SocketAddress socketAddress = new InetSocketAddress(inetAddress, Integer.parseInt(port));
// unbound socket
Socket socket = new Socket();
// TimeoutMs.
int timeoutMs = 2000; // 2 seconds
socket.connect(socketAddress, timeoutMs);
OutputStream out = socket.getOutputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out.write(data.getBytes());
String line = “”;
if (in.ready()){
while((line = in.readLine()) != null){
xml.append(line);
if(line.endsWith(responseEndTag)){
break;
}
}
}
out.close();
in.close();
socket.close();
}
catch (UnknownHostException e) {
xml.append(e.getMessage());
}
catch (SocketTimeoutException e) {
xml.append(e.getMessage());
}
catch (IOException e) {
xml.append(e.getMessage());
}
data = xml.toString();
// pipeline
IDataCursor pipelineCursor_1 = pipeline.getCursor();
//valueList[0] = “data”;
IDataUtil.put( pipelineCursor_1, “data”, data );
pipelineCursor_1.destroy();