Re: A simple connection between 2 computers

The read method returns the total number of bytes read into the buffer, or -1 is there is no more data because the end of the stream has been reached.
So I need to run a loop while the returned value not equal to -1.
But what to do with the array size?The read method ask for a byte array as a parameter so I have to declare it before.
And it's wierd cause the error don't even come from there .. all the erros are output errors and line 24 is the out.write line.

So I got only 2 more questions now:
What to do with the array size?
How do I execute my exe from this byte array?writing it to a file exe suffix?I can't test it right now cause my array got many values that shouldn't be there.
All the default values(zeros) the fill all the empty indexes.

Re: A simple connection between 2 computers

Did the total number of bytes you wrote out to the file match the number in the original file?
Do you have a compare program to compare the input file to the output file? Are the files the same size?

For testing, use a file that is easy to look at to see if there any differences. For example a text file containing simple text like:
abcdefgh.....through yz(26 letters) repeated many times to make a large file.

Re: A simple connection between 2 computers

lol it's funny, I did everything you said before you posted it.
Both of the arrays got the same values and same length.
I tested it with text files and it did worked and created a new one on the client computer with the correct text in it.
Looks like when it comes to exe's/jar files it's another story.
Do you have any idea?

Re: A simple connection between 2 computers

Did you compare the .exe files?

Another idea: write a simple program to create a test file containing byte values from 0 to 255. Then another program to read and verify the file has those values. Send this test file with its 256 different byte values and see if it is received ok. With these programs you could see what byte values are not bring sent correctly.

Re: A simple connection between 2 computers

lol the first exe got 11.7 kb and the new exe got 252 bytes.
I had a mistake, when you print 2 things from diffrent classes the console doesn't changed.
The first ar(server side) got 12028 bytes and the other ar(client side) got 252 bytes.

So it has to be something with the write method.
The api says: "Writes b.length bytes from the specified byte array to this file output stream." which sounds good.

And I did another test, it copy fine txt files with small length.
I tried to copy this txt file:

It recieve the length perfectly and build the array as it should be.
But when it comes to passing the values something is going wrong, after debuging I saw that the loop ran 1 time because the first value that the read method return was -1 which means there is nothing to read.
I printed the array server sided to make sure there is something to read, and there was.

Re: A simple connection between 2 computers

It did worked but not completely because I used writeByte method to send the array length, and this method is limited to a certain number so my new array had 64 indexes.
So I created a new stream and sent a string (array length) and casted it into int and it's working fine!
But now there is a problem in the bytes sending.
Damn why it's so hard to send an int and a byte array.

Re: A simple connection between 2 computers

Re: A simple connection between 2 computers

This class has saved my life, and you lead me to her, thank you!
It's copying txt files 100% every byte is passing to the client even in exe's but when I write the exe I get file is corrupt =\
The exe's byte are the same 100%.
Everything work except of exe's.

Re: A simple connection between 2 computers

When I say that they are 100% the same I speak about the bytes amount in each file as you can see in the picture.
And another proof is that it copying any weight of txt's perfectlly.
So I guess that just writing to a file and save it as an exe is incorrect, there must be another way to convert bytes to exe/jar etc ...