Original Post
Hello, I wish to pose a question to the vast body of knowledge which is GameDev:) For a project in 3rd Comp. Eng., I have to make a P2P file transfer program. I am specifically working on the File Overlay using Kademlia topology. Anyways, the project has to be in Java. I ran into trouble when the .write() function of an OutputStream class does not return an integer (containing the number of bytes written). Here's the story: everything was working, except when transferring non ASCII files (ie. a bitmap or jpeg etc). So, the logical thing to do is move from sending data over a PrintStream to sending it over the OutputStream. So, everything is good while programming, except that .write() returning void looks very fishy based on my socket programming experience in C/C++... anyways, finish the code and test it out. Well, it works some of the time:) Ok, so debugging it reveals that some threads finish the read as expected, while others will read a few bytes and then will wait forever for the rest (example: thread1 could get 1024 out of 1024 bytes as expected. but thread2 could get only 6 out of 1024). Now, .read() actually returns an integer, so I can make sure I read the right amount, but unfortunately I can't see a way to make sure I send the entire array of bytes I give to the .write() function. So, can anyone help me out here? This IS the reason it's not working right (I'll look pretty dumb if it's not:) )? I've checked out some stuff online - SocketChannel has .write which returns integer, but I don't think thats where I should go with this... PS: I would be using .write(byte[], int off, int len) if it would return int - since it doesn't its no different than .write(byte[]) or .write(byte[], int len). GRRRRRR, I wish this were in C++ :) (not at home in Java yet, so I'm biased towards C++, lol) Thanks in advance