22. august 2005 - 15:03Der er
35 kommentarer og 1 løsning
Kan kun overfører ca. 30 kb over sockets
Jeg leger med overførsel af data fra en klient til en anden klient gennem en server. Det seer ud til at virke ca. de første 30 kb og så "hænger" den og kommer ikke videre. Hvis jeg f.eks har en fil på mindre end 30 kb så bliver hele filen overført fra en klient over til den anden klient, mens den hænger hvis filen er over de 30 kb.
Kan nogen komme med et bud til hvad der kan gå galt?
Jeg har ikke noget kode jeg kan vise frem nu, men kan gøre det når jeg kommer hjem...
Starting UploadClientThread Filesize is: 103110 sending: 1000 left of file: 102110 sending: 1000 left of file: 101110 sending: 1000 left of file: 100110 sending: 1000 left of file: 99110 sending: 1000 left of file: 98110 sending: 1000 left of file: 97110 sending: 1000 left of file: 96110 sending: 1000 left of file: 95110 sending: 1000 left of file: 94110 sending: 1000 left of file: 93110 sending: 1000 left of file: 92110 sending: 1000 left of file: 91110 sending: 1000 left of file: 90110 sending: 1000 left of file: 89110 sending: 1000 left of file: 88110 sending: 1000 left of file: 87110 sending: 1000 left of file: 86110 sending: 1000 left of file: 85110 sending: 1000 left of file: 84110 sending: 1000 left of file: 83110 sending: 1000 left of file: 82110 sending: 1000 left of file: 81110 sending: 1000 left of file: 80110 sending: 1000 left of file: 79110 sending: 1000 left of file: 78110 sending: 1000 left of file: 77110 sending: 1000 left of file: 76110 sending: 1000 left of file: 75110 sending: 1000 left of file: 74110 sending: 1000 left of file: 73110 sending: 1000 left of file: 72110 sending: 1000 left of file: 71110 sending: 1000 left of file: 70110 sending: 1000 left of file: 69110 sending: 1000 left of file: 68110 sending: 1000 left of file: 67110 sending: 1000 left of file: 66110 sending: 1000 left of file: 65110 sending: 1000 left of file: 64110 sending: 1000 left of file: 63110 sending: 1000 left of file: 62110 sending: 1000 left of file: 61110 sending: 1000 left of file: 60110 sending: 1000 left of file: 59110 sending: 1000 left of file: 58110 sending: 1000 left of file: 57110 sending: 1000 left of file: 56110 sending: 1000 left of file: 55110 sending: 1000 left of file: 54110 sending: 1000 left of file: 53110 sending: 1000 left of file: 52110 sending: 1000 left of file: 51110 sending: 1000 left of file: 50110 sending: 1000 left of file: 49110 sending: 1000 left of file: 48110 sending: 1000 left of file: 47110 sending: 1000 left of file: 46110 sending: 1000 left of file: 45110 sending: 1000 left of file: 44110 sending: 1000 left of file: 43110 sending: 1000 left of file: 42110 sending: 1000 left of file: 41110 sending: 1000 left of file: 40110 sending: 1000 left of file: 39110 sending: 1000 left of file: 38110 sending: 1000 left of file: 37110 sending: 1000 left of file: 36110 sending: 1000 left of file: 35110 sending: 1000 left of file: 34110 sending: 1000 left of file: 33110 sending: 1000 left of file: 32110 sending: 1000 left of file: 31110 sending: 1000 left of file: 30110 sending: 1000 left of file: 29110 sending: 1000 left of file: 28110 sending: 1000 left of file: 27110 sending: 1000 left of file: 26110 sending: 1000 left of file: 25110 sending: 1000 left of file: 24110 sending: 1000 left of file: 23110 sending: 1000 left of file: 22110 sending: 1000 left of file: 21110 sending: 1000 left of file: 20110 sending: 1000 left of file: 19110 sending: 1000 left of file: 18110 sending: 1000 left of file: 17110 sending: 1000 left of file: 16110 sending: 1000 left of file: 15110 sending: 1000 left of file: 14110 sending: 1000 left of file: 13110 sending: 1000 left of file: 12110 sending: 1000 left of file: 11110 sending: 1000 left of file: 10110 sending: 1000 left of file: 9110 sending: 1000 left of file: 8110 sending: 1000 left of file: 7110 sending: 1000 left of file: 6110
send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 760 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000 send to clients 1000
At upload clienten sendte til alle clienter forbundet til serveren var noget jeg brugte fordi jeg i starten bare skulle have det til at virke. Men det bevirkede at uploaden ikke virkede som du oxo skrev fordi den sendte til sig selv. Da jeg løste det fandt jeg ud af at det stadigvæk ikke virkede, fordi at upload clienten begyndte at sende data, før download clineten havde forbundet sig til serveren. Derfor måtte jeg lave en løkke, der fik upload clienten til at vendte med at uploade filen, før download clienten havde forbundet sig. Og så lykkedes det, efter flere dags kamp :-)
For forståelsens skyld skal det lige siges at upload funktionaliteten bliver brugt i en chat og at det er derfor at der skal være en form for synkronisering mellem klienter før det kan virke.
Nu er jeg imidlertidig løbet ind i et andet problem som jeg ikke kan komme videre med. Første gang client a uploader en fil til klient b går det fint, men gør den det anden gang får jeg en fejl. Men hvis client a forsøger at uploade en fil til client c efter at have uploadet til client b går det fint. Det er ligesomom at den ikke kan uploade 2 gange til samme client. Det virker selvfølgelig hvis jeg genstarter client a.
Jeg giver 200 points hvis du kan give mig et hint der kan løse fejlen?
Her er noget udskrift:
første upload:
2005-08-30 22:19:27,328 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - Try to send 2005-08-30 22:19:27,328 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 16384 2005-08-30 22:19:27,343 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 9896 2005-08-30 22:19:27,625 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 16384 2005-08-30 22:19:27,687 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 11356 2005-08-30 22:19:27,781 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 10220 2005-08-30 22:19:27,859 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 5840 2005-08-30 22:19:27,906 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 4380 2005-08-30 22:19:27,968 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 8760 2005-08-30 22:19:28,062 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 16060 2005-08-30 22:19:28,156 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 8760 2005-08-30 22:19:28,234 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 7300 2005-08-30 22:19:28,250 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 4380 2005-08-30 22:19:28,328 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 11680 2005-08-30 22:19:28,468 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 16060 2005-08-30 22:19:28,609 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 16384 2005-08-30 22:19:28,718 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 14276 2005-08-30 22:19:28,843 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 14600 2005-08-30 22:19:28,968 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 16060 2005-08-30 22:19:29,093 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 16060 2005-08-30 22:19:29,187 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 5840 2005-08-30 22:19:29,281 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 16384 2005-08-30 22:19:29,281 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 1136 2005-08-30 22:19:29,437 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 16384 2005-08-30 22:19:29,546 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 9896 2005-08-30 22:19:29,656 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 16060 2005-08-30 22:19:29,781 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 16384 2005-08-30 22:19:29,812 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 9896 2005-08-30 22:19:29,937 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 16060 2005-08-30 22:19:30,078 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 16384 2005-08-30 22:19:30,171 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 9896 2005-08-30 22:19:30,312 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 16060 2005-08-30 22:19:30,437 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 16384 2005-08-30 22:19:30,484 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 11356 2005-08-30 22:19:30,593 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 11258 2005-08-30 22:19:30,671 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - Finished sending file 2005-08-30 22:19:30,671 INFO [Thread-6] dk.aslani.chat_server.control.FileThread - Closing socket connection....
anden upload:
2005-08-30 22:19:47,671 INFO [Thread-7] dk.aslani.chat_server.control.FileThread - Try to send 2005-08-30 22:19:47,687 INFO [Thread-7] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 4380 2005-08-30 22:19:47,750 INFO [Thread-7] dk.aslani.chat_server.control.FileThread - sending to *** bytes: 13140 2005-08-30 22:19:47,750 ERROR [Thread-7] dk.aslani.chat_server.control.FileThread - Error in sending file java.net.SocketException: Software caused connection abort: socket write error at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92) at java.net.SocketOutputStream.write(SocketOutputStream.java:136) at dk.aslani.chat_server.control.FileThread.run(FileThread.java:71) 2005-08-30 22:19:47,750 INFO [Thread-7] dk.aslani.chat_server.control.FileThread - Closing socket connection....
Og noget kode:
Uploadhandler(server):
public void run(){ while(true){ try{ Socket s = ss.accept();
}catch(IOException io){ log.error("Error in run",io); } } }
FileThread(Server):
public void run(){
SocketClient sc = null; int counter=0; while((sc=uh.getFileToClient(uploadClientName))==null){ log.info("could not find uploadClient: "+uploadClientName+" - "+counter); counter++;
try{ //sleep 10 sec sleep(1000); }catch(InterruptedException e){ log.error("Error in sleep of thread",e); } //stop waiting after 3 min. if(counter==180){ log.info("Giving up to wait after 3 min. uploadClientName: "+uploadClientName); return; } }
byte[] b = new byte[16384]; try{ int n; log.info("Try to send"); long downloadedSize=0; Socket outSocket = sc.getSocket(); if(outSocket != null && !outSocket.isClosed()){ OutputStream os = outSocket.getOutputStream(); while((n = is.read(b)) >= 0) { log.info("sending to "+sc.getUserName()+" bytes: "+n); os.write(b, 0, n); downloadedSize +=n; if(fileSize<=downloadedSize){ break; } } os.flush(); } log.info("Finished sending file");
}catch(Exception e){ log.error("Error in sending file",e); } finally{ if(!socket.isClosed()){ log.info("Closing socket connection...."); try{socket.close();}catch(IOException io){log.error("Error in closing socket",io);} } } }
DownloadClient:
private void download(){
System.out.println("Starting DownloadClientThread"); System.out.println("Saving file: "+file.toString()); try{ OutputStream os = new FileOutputStream(file); byte[] b = new byte[16384]; int n; long downloadedSize=0; while((n = is.read(b)) >= 0) { System.out.println("receiving "+n); os.write(b, 0, n); downloadedSize +=n; if(fileSize<=downloadedSize){ break; } } System.out.println("Finished receiving file"); os.flush();
Det vil jeg mene, dette udskrift er fra uplaod clienten efter 2 upload forsøg:
Starting UploadClientThread Filesize is: 403094 sending: 16384 left of file: 386710 sending: 16384 left of file: 370326 sending: 16384 left of file: 353942 sending: 16384 left of file: 337558 sending: 16384 left of file: 321174 sending: 16384 left of file: 304790 sending: 16384 left of file: 288406 sending: 16384 left of file: 272022 sending: 16384 left of file: 255638 sending: 16384 left of file: 239254 sending: 16384 left of file: 222870 sending: 16384 left of file: 206486 sending: 16384 left of file: 190102 sending: 16384 left of file: 173718 sending: 16384 left of file: 157334 sending: 16384 left of file: 140950 sending: 16384 left of file: 124566 sending: 16384 left of file: 108182 sending: 16384 left of file: 91798 sending: 16384 left of file: 75414 sending: 16384 left of file: 59030 sending: 16384 left of file: 42646 sending: 16384 left of file: 26262 sending: 16384 left of file: 9878 sending: 9878 left of file: 0 Finished sending file closing socket connection...
Starting UploadClientThread Filesize is: 459049 sending: 16384 left of file: 442665 sending: 16384 left of file: 426281 sending: 16384 left of file: 409897 sending: 16384 left of file: 393513 java.net.SocketException: Software caused connection abort: socket write error closing socket connection... at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92) at java.net.SocketOutputStream.write(SocketOutputStream.java:136) at java.io.BufferedOutputStream.write(BufferedOutputStream.java:105) at dk.aslani.chat_client.control.UploadClientThread.upload(UploadClientThread.java:78) at dk.aslani.chat_client.control.UploadClientThread.run(UploadClientThread.java:107)
Jep du starter dk.aslani.chat_server.control.Server for at køre serveren og dk.aslani.chat_client.view.AppletForm for at køre klienterne. Og der er brugt ant.
BUILD FAILED C:\Chat\chat_client\nbproject\build-impl.xml:289: The following error occurred while executing this line: C:\Chat\chat_client\nbproject\build-impl.xml:189: Classname must not be null.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.