You have to reassembly the complete message by using decoder. Please read
the SumUp example first.

2007/5/17, 李健 <[EMAIL PROTECTED]>:

   i'v tested to send request like "123" using DataOutputStream

   byte[] req = "123".getBytes()
   dataOutputStream.writeInt(req.length);
   dataOutputStream.write(req);
   dataOutputStream.flush();

   i tried to send this request 10 times, the server received data like
this:

   recevieLen=7 [ 0 0 0 3 49 50 51 ]
   recevieLen=7 [ 0 0 0 3 49 50 51 ]
   recevieLen=7 [ 0 0 0 3 49 50 51 ]
   recevieLen=1 [ 0 ]
   recevieLen=1 [ 0 ]
   recevieLen=1 [ 0 ]
   recevieLen=1 [ 3 ]
   recevieLen=3 [ 49 50 51 ]
   recevieLen=1 [ 0 ]
   recevieLen=1 [ 0 ]
   recevieLen=1 [ 0 ]
   recevieLen=1 [ 3 ]
   recevieLen=3 [ 49 50 51 ]
   recevieLen=1 [ 0 ]
   recevieLen=1 [ 0 ]
   recevieLen=1 [ 0 ]
   recevieLen=1 [ 3 ]
   recevieLen=3 [ 49 50 51 ]
   recevieLen=1 [ 0 ]
   recevieLen=1 [ 0 ]
   recevieLen=1 [ 0 ]
   recevieLen=1 [ 3 ]
   recevie=3 [ 49 50 51 ]
   ......


   i'v looked into JDK source code about DataOutputStream:
   public final void writeInt(int v) throws IOException {
       out.write((v >>> 24) & 0xFF);
       out.write((v >>> 16) & 0xFF);
       out.write((v >>>  8) & 0xFF);
       out.write((v >>>  0) & 0xFF);
       incCount(4);
   }
   it will cal out.write() for every byte, so my server'll recevie length
value 4 times.

   why the first 2 or 3 times request will be OK (the server can get the
whole 7 bytes), who can gvie me some help to handle this problem, thanks a
lot.

======== 2007-05-15 17:08:29: ========

Hi, All

   i wanna to use MINA to improve my ApplicationServer, the old
application's socket part is developed using DataInputStream &
DataOutputStream in both server and client side. we wrote data package
length at the begining for ervry request and response data. the code looks
like this

   // for request
   byte [] request = ...
   int reqLen = request.length;
   dataOutputStream.writeInt(reqLen);
   dataOutputStream.write(request);
   dataOutputStream.flush();
   ...
   // for response
   int resLen = dataInputStream.readInt();
   byte[] response = new byte[resLen];
   dataInputStream.read(response);
   ...


   i'v tried to use MINA to handle the request sent by my old clients(the
clients have been deployed in many area and CodeChanging is forbidden),
because of the noblocking of NIO, when one client calls writeInt(), write(),
flush() methods orderly, my IoHandler would recevie data partly in many
times. so in  IoHandler.messageRecevied(), it couldn't get the whole
request data to do the business logic.

   who can give me some advice to handle tihs?

Best Regard!
                     LJ

    2007-05-15


= = = = = = = = = = = = = = = = = = = = = =

Reply via email to