Results 1 to 2 of 2
Thread: socket DataOutput problems
- 12-17-2009, 07:43 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 26
- Rep Power
- 0
socket DataOutput problems
Hi,
For my client/server program i am having problems with my client recieving the correct amount of data. when i step through the client it does not always receive all the bytes for the first stream. Edit: My client program will just freeze after during the 2nd transfer or the 6th. its at random times. the file does transfer but information on the clients screen does not update.
this is the code for my server
clientJava Code:FileInputStream fileInput = new FileInputStream(file); //create fileInputStream of file DataOutputStream stream = new DataOutputStream(socket.getOutputStream()); //creat DataOutputStream of the socket byte[] bb = new byte[10000]; //create a byte that stores 10000 bytes start = System.currentTimeMillis(); //get the current time in milliseconds while (true) { //loop untill file is sent int result = fileInput.read(bb); //read 10000 bytes of the file into result if (result == -1) { //check if end of file has been read break; //exit while loop } stream.write(bb, 0, result); //send 10000 bytes of file to the client stream.flush(); }
edit: also if i step through the server the client and the serve work just fine. I can't figure out why my client will occasionally just freeze on me.Java Code:DataInputStream dataInput = new DataInputStream(socket.getInputStream()); //create a new instance of a DataInputStream in order to get data from server FileOutputStream fileOutput = new FileOutputStream(path.trim() + "\\" + newFileName.trim()); //create new instance of FileOutputStream to write the file to the clients computer byte[] bb = new byte[10000]; //create a new instance of a byte while (true) { int result = dataInput.read(bb); //read 10000 bytes and place bytes in variable called result fileOutput.write(bb, 0, result); //write a file on input if (fileSize == result) { //check if result is equal to the filesize break; //break while loop } fileSize -= result; //subtract result from fileSize }Last edited by gisler; 12-17-2009 at 09:04 PM.
- 12-17-2009, 09:04 PM #2
Member
- Join Date
- Apr 2009
- Posts
- 26
- Rep Power
- 0
Similar Threads
-
append response to the request from Socket and write to another socket
By vaibhav_singh_vs@yahoo.co in forum NetworkingReplies: 3Last Post: 04-17-2009, 07:02 PM -
help about Socket
By fahien_akim in forum New To JavaReplies: 0Last Post: 04-16-2009, 10:41 AM -
Socket
By rob in forum New To JavaReplies: 1Last Post: 03-19-2009, 02:24 PM -
Socket
By vortex in forum New To JavaReplies: 2Last Post: 05-25-2008, 06:41 AM -
XML through a socket
By Heather in forum XMLReplies: 2Last Post: 07-04-2007, 09:31 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks