Server reply coming through as -1

djb dbrownell83 at hotmail.com
Tue Jun 1 07:22:51 EDT 2010


Hi,

I've written my first Netty server, which hosts a program for C++ clients... 
It receives a request, processes and replies.  At the moment, I'm still
testing a Java-Java version.  

I'm using the IntegerHeaderFrameDecoder from the Javadocs, and am receiving
my client's messages.  But when I reply in my server's message handler, it
goes ahead and sends it, and then my client receives -1.

------------------------------------------
Client code:
------------
socket = new Socket("localhost", MultiThreadedClient.port);

BufferedOutputStream out = new BufferedOutputStream(
		socket.getOutputStream());
BufferedInputStream in = new BufferedInputStream(
		socket.getInputStream());

byte[] data = claim.getBytes("UTF-8");

out.write( getByteInt(false, data.length));
out.write( data ); 
out.flush();
System.out.println("Sent claim to server.");

------------------------------------------
Goes to this Server code:
------------
//(receives request, sends back results)
byte[] data = results.getXMLString().getBytes("UTF-8");
      
ChannelBuffer replyBuffer = (ChannelBuffer)e.getMessage();
replyBuffer.resetWriterIndex();  //removing this causes
ArrayOutOfBoundsException instead of -1
replyBuffer.writeInt(data.length);
replyBuffer.writeBytes(data);
----------------------------------------
Comes back to client:
------------

int length = in.read();
System.out.println("Got Length of reply: " + length); //<<<Outputs -1 here
byte[] reply = new byte[length];
in.read(reply);
System.out.println(new String(reply));
------------------------------------------

Please advise why the client thinks it is EOF...

Thanks
Daniel
-- 
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Server-reply-coming-through-as-1-tp5125569p5125569.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list