Here goes the solution.
As my project is related to an embedded micro-controller, A little info for the programmers.
Any serial communication protocol cannot transmit all the data at a single go. It depends on the periodicity on which your transmit function is being called.
i.e. it depends in which ms task your function is called is you are using an RTOS.
So if the data is large say 1024 bytes it may not be possible to transmit all data at a single go i.e. at the single call of a function and it may need multiple cycles to complete the job.
As the PC side is much faster than the controller side, the PC has to wait till all data is received before it starts processing the data.
Ok, Now coming to the solution for above problem ,
I know the number of bytes i am expecting in each transaction, lets say 1000 bytes.
// Code snippet
public void serialEvent(SerialPortEvent Ack_Rec) {
if (Ack_Rec.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
try {
while (in.available() > 0) {
int totalbytesreceivedinSession = in.read(sessionRead);
for (int bytesreceieved = 0; bytesreceieved < totalbytesreceivedinSession; bytesreceieved++) {
temporaryPacket[recDataCount++] = sessionRead[bytesreceieved];
}
if(recDataCount == 1000){
//Process the data
}
}
Hope this is helpfull,
Cheers!