We've created a java servlet/java application to handle file uploads. The servlet gets a multi-part form request that has name value pairs and a file. The servlet then parses through the header, separates the name value pairs into an object and streams the file over to the java application through a socket. Here's the problem.

The java application receives the file, does some processing, then sends a response back to the java servlet. Or at least, that's what we want to happen. The problem is the fact that the java application never quite knows when the end of file is reached. So it's getting binary information from the servlet (a buffer at a time). Once it gets everything, it's still waiting for more because it doesn't know that it got everything. On the other end, the servlet has sent everything and is waiting for the response from the java application so that it can display the results of the file operation to the user. Both sides are waiting, nothing is happening and the user finally receives a read error (because the servlet never got it's response to show the user).

We thought about sending very specific binary delimeters. For example, take the string "^*^*", convert that to binary, then send that. But there's no real delimeter that you can use and ensure won't be part of the upload. Furthermore, this method slows things down to a crawl. Why? Because the java app has to check each time it receives a buffer to see if it contains the delimeter. We thought we could solve that problem by checking for the delimeter only when the buffer size was less than what was specified. In other words, we tell the servlet to stream the file to the app in, let's say, 10k chunks. Any time the app gets less than a 10k chunk, that must be the last transmission, right? Just ensure that by checking for the delimeter and you're fine? Well, java doesn't necessarily have to send the chunk size that you tell it to send it. The number that you specify just simply tells java what the maximum you want to send at one is. There's actually other implications but I won't get into them. The other solution is to check with every chunk. That takes about 100 years and is not viable.

I've come a long way to ask this question, so here it is. What is the eof delimeter? If I knew what that was, I could send it and the java app would know to stop looking for more bytes. Realize that closing the stream used to send info over the socket is not an option because we have to wait for a response from the java app. Thanks for your help.