我正在创建一个Android应用程序,它作为一个监听器,等待监视器通过Wi-Fi通过HL7协议发送信息的代码。
我正在使用Hapi应用程序测试我的应用程序并收到消息,但我无法将ACK发送回Hapi测试面板。任何人都可以帮助我吗?
public void onCreate()
{
super.onCreate();
serverThread = new Thread(new Runnable() {
public void run()
{
try
{
PrintWriter mOut;
Looper.prepare();
socket = new ServerSocket(8080);
socket.setReuseAddress(true);
socket.setPerformancePreferences(100, 100, 1);
while (!stop)
{
Socket accept = socket.accept();
accept.setPerformancePreferences(10, 100, 1);
accept.setKeepAlive(true);
try
{
in = new BufferedReader(new InputStreamReader(accept.getInputStream()));
//Each message has 15 segments
int cont=0;
for (cont=0;cont<15;cont++){
if (cont==0){
aux = in.readLine();
aux=aux.substring(1);
if (aux.contains(inicio)){
hl7Message=aux+separator2;
}
else{
Log.v("Fail", "Error, the received data does not " +
"follow the HL7 protocol");
break;
}
}
hl7Message+=in.readLine()+separator2;
Log.v("hl7",hl7Message);
ACK= hl7Parser(hl7Message);
mOut.print(ACK);
//Wait 5 minutes for the next message comming from the monitor
//while the conexion is available
//Thread.sleep(INTERVAL);
}
}
catch (IOException e2)
{
e2.printStackTrace();
}
displayNotification(hl7Message);
}
}
catch (Throwable e)
{
e.printStackTrace();
Log.e(getClass().getSimpleName(), "Error in Listener",e);
}
try
{
socket.close();
}
catch (IOException e)
{
Log.e(getClass().getSimpleName(), "keep it simple");
}
}
},"Server thread");
serverThread.start();
}
这就是我通过mOut发送ACK的方式:
public String hl7Parser(String hl7Message){
String[] fieldsOfMessage= null;
fieldsOfMessage=hl7Message.split(separator2);
//Message Header
MSH=fieldsOfMessage[0];
int[] indice;
//MSH SEGMENT
indice=get_indice(MSH);
String sending_application, sending_facility, receiving_application,
receiving_facility, date, message_type,
message_control_id, processing_ID, version, sequence_number,
accept_ack_type, app_ack_type, country_code, principle_language, message_profile_id;
sending_application=MSH.substring(indice[1]+1,indice[2]);
Log.v("Sending_application",sending_application);
sending_facility=MSH.substring(indice[2]+1,indice[3]);
Log.v("Sending_facility",sending_facility);
receiving_application=MSH.substring(indice[3]+1,indice[4]);
Log.v("Receiving_application",receiving_application);
receiving_facility=MSH.substring(indice[4]+1,indice[5]);
Log.v("Receiving_facility",receiving_facility);
date=MSH.substring(indice[5]+1,indice[6]);
Log.v("Date",date);
message_type=MSH.substring(indice[7]+1,indice[8]);
Log.v("Message_type",message_type);
int tr=message_type.indexOf("^");
String type=message_type.substring(tr+1);
message_control_id=MSH.substring(indice[8]+1,indice[9]);
Log.v("Message_control_id",message_control_id);
processing_ID=MSH.substring(indice[9]+1,indice[10]);
Log.v("Processing_ID",processing_ID);
version=MSH.substring(indice[10]+1);
Log.v("Version",version);
ACK=inicio+"|"+receiving_application+"|"+receiving_facility+"|"+sending_application+"|"+sending_facility+"|"+standard_date+"||"+"ACK^"+type+"|"+message_control_id+"|"+processing_ID+"|"+version+"\n"+"MSA"+"|"+"AA"+"|"+message_control_id;
return ACK;
}
private int [] get_indice(String line){
int l=line.length();
char d='|';
char[] letras = line.toCharArray();
int[] indices = new int[1000];
int s = 0;
for (int i = 0; i < l; ++i)
{
if (d == letras[i])
{
indices[s]=i;
s++;
}
}
return indices;
}
我已经尝试了但是我遇到了一些与java和android冲突相关的错误,这就是我试图这样做的原因,但是我把这个错误带到了测试面板中: