I have a client/server application suite built using J2SE. The two
applications communicate using HTTP. The client connects to the
server using the high-level URL and HttpURLConnection classes. The
server listen for and services client requests using the low-level
ServerSocketChannel and SocketChannel classes. The problem I'd like
some advice on occurs when the server tries to read the content of a
client's PUT (or POST) request. The server discovers the content
length by querying the Content-Length HTTP header. But only a portion
of the data can be read from the server's InputStream. After a
certain point the server ends up permanently blocked as it tries to
read the number of bytes indicated by the value of the Content-Length
header.
Now here's the kicker... It only happens (and always happens) if
either the client or server or both are MacOSX.
I have several years experience working with Java. But I also know
there are programmers out there with a much firmer grasp on the
environment than I do. So I'd appreciate any help that might come my
way. What I'd like to do is articulate all the obvious questions
someone might have about my problem and hope that the participants of
this forum can help me zero in on what I'm doing wrong -- or what is
wrong with the Mac JVM, if that ends up being the case (it never does).
* The problem occurs when 1) the client is running under MacOSX and
the server is running under Windows XP, 2) client = XP & server =
Mac, or 3) client = Mac & server = Mac. The problem does not occur if
both client and server are XP based -- whether on the same XP box or
different ones.
* All participants are on the same subnet (or even on the same
machine). The activity monitors on all machines show reasonable CPU
and network traffic.
*If I suspend the blocked client thread the stack crawl looks like
the following...
* The server code that is attempting to read the incoming content
looks something like this...
public static byte[] readBytes(SocketChannel aSocketChannel, int
aMaxBytes) throws IOException {
InputStream stream = Channels.newInputStream(aSocketChannel);
// InputStream stream = aSocketChannel.socket().getInputStream
(); // either way
int length = 0;
byte[] bytes = new byte[aMaxBytes];
while (length < aMaxBytes) {
int count = stream.read(bytes, length, aMaxBytes - length);
if (count < 0) {
byte[] buffer = new byte[length];
System.arraycopy(bytes, 0, buffer, 0, length);
return buffer;
}
length += count;
}
return bytes;
}
* The content that is being exchanged from client to server is
textual. But the encoding of bytes to characters (and back) is done
using the same character set on both sides. The problem occurs
regardless of which encoding I use (UTF-8 or ISO8859-1).
* I can see from dumping the data to a console window that the
content being received is the end part of what is being sent. Stated
the other way, the part of the text that I'm sending that is not
being received is the beginning. So if the text being sent consists
of 100 lines, for example, I'm receiving something like the final 60
lines of that text on the receiving end.
Any suggestions would be greatly appreciated.
- Sparky
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden