Hi Markus,

Which version of MINA are you using?  We've just released a new
version that fixes the problem you are experiencing:

http://www.apache.org/dyn/closer.cgi/mina/1.1.1/

We didn't announce the new release because of propagation delay
between mirrors.  Please use the backup sites if you get 404.

HTH,
Trustin

On 7/18/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
Hi,

I have problems with garbled data send by a StreamIOHandler. Here is my
code (short Version ;-):

Server:
=====

new SocketAcceptor().bind(
   new InetSocketAddress(port),
   new StreamIoHandler() {
       protected void processStreamIo(
           IoSession    session,
           InputStream  in,
           OutputStream out
       ) {
          new Thread(new Worker(in, out)).start();
      }
   },
   new SocketAcceptorConfig()
);


public class Worker implements Runnable {
 private InputStream is;
 private OutputStream os;

 public Worker(InputStream is, OutputStream os) {
   this.is = is;
   this.os = os;
 }

 public void run() {
   // read request
   ...

   // write response

   byte[] buffer = new byte[1024];
     for (int i = 0; i < 100; i++) {
       for (int j = 0; j < buffer.length; j++) {
       buffer[j] = (byte) (i + j);
       }
       // buffer.clone() because of Bug DIRMINA-369
       os.write((byte[]) buffer.clone());
       // os.flush() to wait for completion (necessary?)
       os.flush();
     }
  }
}


Client
=====

Socket socket = new Socket(adress, port);

// write request

socket.getOutputStream(). ...;

// read response

InputStream is = socket.getInputStream();
byte[] buffer = new byte[1024];
int size = 0;
int blockCount = 0;
while ((size = is.read(buffer)) > 0) {
 for (int i = 0; i < buffer.length; i++) {
   if ((byte) (blockCount + i) != buffer[i]) {
     throw new RuntimeException("garbled data");
   }
 }
 blockCount++;
}


---------------------------

If I choose the buffer for send and receive small enough (e. g. 64 byte)
everthing works. But with a buffersize of 1024 bytes the response data is
garbled. If I insert a sleep of 50 ms at serverside between every write,
it works again, even with a buffersize of 1024 bytes.

Thanks for help
Markus


--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Reply via email to