if (st != null)
return st;
Socket s = null;
try {
Map<String, Object> prms = cntx.getGroupParams(msg_grp_in);
SAMsg q = new SAMsg();
PrmInterface prmi;
{
prmi = q.getPrmInterface();
for(Map.Entry<String, Object> prm : prms.entrySet()) {
String key = prm.getKey();
String[] fn = cntx.getFullName(key);
prmi.setField(fn[1], Strings.getString(cntx.getPrmString(key)));
}
}
s = new Socket(host, port);
System.out.println("Opened link " + Sockets.getNameLink(s));
InputStream is = s.getInputStream();
OutputStream os = s.getOutputStream();
SAMsg in = new SAMsg();
SAMsg result = new SAMsg();
int enq = is.read();
System.out.print("<-- " + toHexString(enq));
if (enq != SAMsg.ENQ)
throw new TaskException(State.DONE_ERR, "Incorrect the first signal from host");
q.sendTo(s.getOutputStream());
System.out.print("\n-->");
q.printTo(System.out);
System.out.println();
String v;
for (String n : prmi.getFieldNames()) {
v = prmi.getField(n);
System.out.println(n + " = " + v);
}
int ch;
PrmInterface inpi = in.getPrmInterface();
CloseableOutputStream osc = in.getOutputStream();
System.out.print("\n<--");
boolean end = false;
while (!end && (ch = is.read()) != -1) {
System.out.print(" ");
System.out.print(toHexString(ch));
osc.write(ch);
if (osc.isClosed()) {
switch(Integer.parseInt(inpi.getField("type"))) {
case SAMsg.STX:
System.out.println();
PrmInterface rpi = result.getPrmInterface();
for (String n : inpi.getFieldNames()) {
v = inpi.getField(n);
rpi.setField(n, v);
System.out.println(n + " = " + v);
}
end = true;
break;
case SAMsg.ACK:
System.out.print("\n<--");
break;
case SAMsg.ENQ:
System.out.print("\n<--");
break;
default:
System.out.print("\n<--");
throw new TaskException(State.DONE_ERR, "Incorrect response from host");
}
in.reset();
osc = in.getOutputStream();
}
}
os.write(SAMsg.ACK);
System.out.print("\n--> " + toHexString(SAMsg.ACK));
os.write(SAMsg.EOT);
System.out.println("\n--> " + toHexString(SAMsg.EOT));
PrmInterface rpi = result.getPrmInterface();
StringList flds = rpi.getFieldNames();
for (String fld : flds) {
cntx.setPrmByFullName(msg_grp_out + "/" + fld, rpi.getField(fld), false);
}
} catch (UnknownHostException e) {