Hi,
There are two applications.The communication between the two application is through socket.
The code that is writing on the socket is as follows:
public boolean sendAlarmWithSize(int size_, String alarm_) throws Exception
{
_dataOutputStream.writeShort(size_);
_dataOutputStream.writeUTF(alarm_);
return true;
}
After writing on the socket i put the print statement in writeShort method of API.It is printing the size_ correct.
At the receiving end for reading from the socket the following code is used:
private Payload readMessages(InputStream in)
throws IOException, java.text.ParseException, InvalidMessageFormat {
PropertyList prop = new PropertyList();
String propertyStr, contentType = null, action = null;
Object obj;
DataInputStream dataStream = new DataInputStream(in);
int numAlarms = dataStream.readShort();
CircuitMessage[] circuitAlarms = new CircuitMessage[numAlarms];
for (int i = 0; i < numAlarms; i++) {
propertyStr = dataStream.readUTF();
if (Logger.DEBUG && myDebug != null) {
myDebug.out(5,"Message Received - " + propertyStr);
}
obj = prop.objectFrom(propertyStr);
if (obj instanceof java.util.Hashtable) {
java.util.Hashtable hash = (java.util.Hashtable)obj;
contentType = (String) hash.get("<content-type>");
action = (String) hash.get("<action-type>");
obj = mssgFactory.digest(hash);
if (obj instanceof CircuitMessage) {
circuitAlarms[i] = (CircuitMessage) obj;
}
} else {
// skip this message because I don't recognize it.
System.out.println(obj);
}
}
Payload payload = new Payload();
payload.payload = circuitAlarms;
payload.contentType = contentType;
payload.action = action;
return payload;
}
In the above code after reading from the stream using readShort() the value is different than the one we wrote on the stream.At the same time readUTF() is throwing UTFDataformat exception. I hope some one can help me .
Thanks in advance,
MSR
There are two applications.The communication between the two application is through socket.
The code that is writing on the socket is as follows:
public boolean sendAlarmWithSize(int size_, String alarm_) throws Exception
{
_dataOutputStream.writeShort(size_);
_dataOutputStream.writeUTF(alarm_);
return true;
}
After writing on the socket i put the print statement in writeShort method of API.It is printing the size_ correct.
At the receiving end for reading from the socket the following code is used:
private Payload readMessages(InputStream in)
throws IOException, java.text.ParseException, InvalidMessageFormat {
PropertyList prop = new PropertyList();
String propertyStr, contentType = null, action = null;
Object obj;
DataInputStream dataStream = new DataInputStream(in);
int numAlarms = dataStream.readShort();
CircuitMessage[] circuitAlarms = new CircuitMessage[numAlarms];
for (int i = 0; i < numAlarms; i++) {
propertyStr = dataStream.readUTF();
if (Logger.DEBUG && myDebug != null) {
myDebug.out(5,"Message Received - " + propertyStr);
}
obj = prop.objectFrom(propertyStr);
if (obj instanceof java.util.Hashtable) {
java.util.Hashtable hash = (java.util.Hashtable)obj;
contentType = (String) hash.get("<content-type>");
action = (String) hash.get("<action-type>");
obj = mssgFactory.digest(hash);
if (obj instanceof CircuitMessage) {
circuitAlarms[i] = (CircuitMessage) obj;
}
} else {
// skip this message because I don't recognize it.
System.out.println(obj);
}
}
Payload payload = new Payload();
payload.payload = circuitAlarms;
payload.contentType = contentType;
payload.action = action;
return payload;
}
In the above code after reading from the stream using readShort() the value is different than the one we wrote on the stream.At the same time readUTF() is throwing UTFDataformat exception. I hope some one can help me .
Thanks in advance,
MSR