Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

UTFDataFormatException  RSS feed

 
mupparaju srinivasa rao
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am having two applications.In one application,one thread writes the data on the socket using writeUTF() method and in other application another thread reads the data using readUTF method.The readUTF method is throwing UTFDataFormat exception very frequently(after reading~100 alarms data).If i run the 2 applications on two different machines th UTFDataFormat exception is thrown(after reading ~1500 alarms data).The jdk version is 1.4.0.
The reading thread:
public void run() {
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);
}
}



The writting thread is:
public void run(){
public boolean sendAlarmWithSize(int size_, String alarm_) throws Exception
{
try
{
Logger.log(Logger.Normal, "SocketUtilities sendAlarmWith Size= "+size_);
Logger.log(Logger.Normal, "SocketUtilities sendAlarmWith alarm_= "+alarm_);
//_dataOutputStream.flush();
_dataOutputStream.writeShort(size_);
TotalAlarmsSendSofar++;
Logger.log(Logger.Error, "SocketUtilities sendAlarmWith alarm???,TotalAlarmsSendSofar = "+TotalAlarmsSendSofar);
_dataOutputStream.writeUTF(alarm_);
return true;
}catch(UTFDataFormatException utf)
{
Logger.log(Logger.Error, "SocketUtilities sendAlarmWith utf.toString() "+utf.toString());
return false;
}

catch(IOException ie)
{Logger.log(Logger.Error, "SocketUtilities sendAlarmWith ie.toString() "+ie.toString());
return false;
}
}


I pasted a part of code.

Please help me.

regards,
MSR
 
Joe Ess
Bartender
Posts: 9425
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You write a number and a UTF String to a stream. You read out a number and expect it to be followed by that number of UTF Strings. If that number is anything but 1, you will attempt to read a short as a UTF string and get an exception.
 
mupparaju srinivasa rao
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thank you for reply.
I am always writing 1 in writeShort method.When the problem occured at reading side the readShort is returning 1280(which it should be one).Even in this case while reading the first string using readUTF it is throwing UTFDataFormatException.
Earlier the writing alarms on socket application was in Object C language and reading from socket application is in java 1.4.0.
Now after converting Writing alarm application also into java tis problem is occuring.

regards,
MSR
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!