Paul Clapham wrote:My guess: Line 33 in your Server code throws an exception because that file doesn't exist. That causes the socket to be forced closed as the server crashes, hence the error at the client side.
There's plenty more things waiting to go wrong in that code, but I think that's your immediate problem.
There's plenty more things waiting to go wrong in that code, but I think that's your immediate problem
Paul Clapham wrote:Can you explain why your server code reads data from the socket, then does nothing with it? And why does it attempt to copy a file to itself?
Also you have numerous bad practices in your code. You use DataInputStream even though you aren't using any of its features. That's unnecessary. You use a ridiculously large buffer when you read the file in your client, and you assume without proof that the read from the file will fill the buffer. If the file is very large you will not have enough memory for the buffer, either. You should use a fixed-size buffer (as in your server code) and write the loop with copies from the file to the socket. In your server you have a magic number (3261440) for your buffer size -- where did that come from?
Can you explain why your server code reads data from the socket, then does nothing with it? And why does it attempt to copy a file to itself?
In your server you have a magic number (3261440) for your buffer size -- where did that come from?
Paul Clapham wrote:Starting at line 37 in your server you have some perfectly good code which copies data from an input stream to an output stream.
You want to copy data from the socket's input stream to that output stream, right?
Then remove all the code before line 37 which doesn't contribute to that process (which is a large chunk of code). Leave only code which copies from the socket's input stream to the file's output stream.
Mads Nielsen wrote:I have removed the code you suggested.
Paul Clapham wrote:
Mads Nielsen wrote:I have removed the code you suggested.
Really?
Let me be blunt, then. Lines 20 to 27 in the code you posted should be thrown away. Once you have done that, fix the remaining code so that it copies from the socket's input stream.`
fix the remaining code so that it copies from the socket's input stream.[/
Mads Nielsen wrote:If i knew how i would not have used this forum.
Paul Clapham wrote:
Mads Nielsen wrote:If i knew how i would not have used this forum.
You seem to be under the impression that this forum is a code-writing or homework-doing service. It isn't. I can't believe that you don't know what to do now; did you not write the original code yourself? Anyway, you're going to have to explain what your problem is. Just saying "I don't know what to do" isn't going to get you anywhere.
You seem to be under the impression that this forum is a code-writing or homework-doing service
I can't believe that you don't know what to do now
Mads Nielsen wrote:This code is 100% percent for my own purposes. I think its ok that you tell me how to fix the problem when i already have 95% of the code.
Paul Clapham wrote:Okay. You would copy the data from the socket's input stream. (I didn't think I should have to tell you that because your original post had code which read data from the socket's input stream.)
No thanks. We have all the government we need. This tiny ad would like you to leave now:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|