ERLEDIGT
NEIN
NEIN
ANTWORTEN
6
6
ZUGRIFFE
651
651
EMPFEHLEN
-
15.01.10 11:12 #1
- Registriert seit
- Jan 2010
- Beiträge
- 8
Hallo zusammen,
habe folgendes Problem und sitzte bereits seit 2 wochen daran und langsam läuft mir die zeit davon, benötige also dringend hilfe und hoffe das ihr mir helfen könnt.
Ich habe ein programm welches eine menge an Dateien verschickt und resultate dafür bekommt.(grobe beschreibung meines programms).
auf dem Client möchte ich eine funktion haben welche einen Vector<File> v als param bekommt und für jedes einzelne File aus Vector eine procedure ausführt.
Files sind meist .sh oder .bat
beschr. für meine funktion sendFilesfromVector
i<v.size
v.get(i) existiert
sende dateinamen an server
sende datei an server
empfange resultat
empfange resultatsdatei
i++
ende
es funktioniert eigentlich auch für den ersten durchlauf, wäre nett wenn jemand dies mal ausführen könnte und sich die meldung anschauen könnte.
ich möchte allerdings das die verbindungs vom client permananet steht auch wenn keine daten verschickt werden.
Das problem liegt darin client.startprocedure ausgeführt funktioniert doch beim zweiten anlauf kommt nur misst und er bleibt irgendwo stecken.
BRAUCHE dringend hilfe danke.
Wie gesagt eigentlich funktioniert es doch bin mit meinem latein am ende
hab jetztt nur eine art modul programmiert um es übersichtlicher zu gestallten
ps. ausführen könntet ihr eine mdFolder.bat wählt sie einfach im chooser aus.
Ich weiss sieht nach viel aus ist aber denke ich nur eine kleinigkeit die ich nicht beachtet habe
THANK U ALLGeändert von Stiffler66 (19.01.10 um 19:52 Uhr)
-
Moin,
also ich würde gerne mal wissen womit du das Programmiert hast? Mit einem Texteditor?
Da ist soviel durcheinander und ganz merkwürdige Aufrufe!
Aber das was du machen möchtest Klingt sehr nach einer Aufgabe du du mittels RMI besser und effektiver lösen könntest!
Hast eventuell ein UML Diagramm oder so das man mal sehen kann was du bezweckst?
Gruß XeoXWenn du jemandem auf die Brille trittst, erinnere ihn: Man sieht nur mit dem Herzen gut.
(Antoine de Saint-Exupéry)
-
17.01.10 14:35 #3
- Registriert seit
- Jan 2010
- Beiträge
- 8
Hi XeoX,
ersteinmal danke das du geantwortet hast!
also habe es mit rmi versucht kam aber auf rmi nicht klar !
((
Ich glaube rmi würde mich nur 1/3 des aufwandes kosten den ich jetzt habe würde dir gerne den programmablaufplan und ein sequenz diagramm schicken.
-
19.01.10 19:50 #4
- Registriert seit
- Jan 2010
- Beiträge
- 8
hier die überarbeitete version.
main() wird später als funktion benutzt um einen vector mit files zu bearbeiten also main()=sendVectorFiles() im hauptprogramm.
ablauf:
1)client verbindet sich zu server und verbindung steht bis das client programm beendet wird
2)client ruft vector<File> v auf und solange i<v.getsize()
-client->sende dateinamen von v.get(i)
-client->sende datei v.get(i)
-client->empfange resultat vom server für v.get(i)
i++
3)client ruft neuen vector auf.... wieder der selbe ablauf
PROBLEM -wenn ich sage ich will in einer for 100 Vector<File> bearbeiten macht er bei 6 schluss
brauche dringend hilfe seit 3 wochen am selben problem.
wählt irgendwelche dateien aus .txt.bat..... im moment teste ich nur das dateien hin schicken und einen festen wert zurück bekommen mehr brauch ich auch nicht
DANKEEE im Voraus
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
import java.net.*; import java.util.StringTokenizer; import java.io.*; import javax.swing.JOptionPane; public class Server { private DataOutputStream dos = null; private DataInputStream dis = null; private Socket socket = null; private ServerSocket serversocket = null; private String basePath = "c:/tmpServer/"; private FileOutputStream fileoutStream = null; private ServerExecuter scriptexecuter = new ServerExecuter(); //-------------------------------------------------------------------------------// private boolean closeConnection() { try { dos.close(); dis.close(); socket.close(); serversocket.close(); return true; } catch (IOException e) {e.printStackTrace();return false;} } //-------------------------------------------------------------------------------// private File receiveFile(String filename) { File base = new File(basePath); File toExecfile = new File(basePath + filename); try { if (base == null || !base.exists()) { System.out.println("return basePath problem on server"); return null; } if (!toExecfile.exists())toExecfile.createNewFile(); fileoutStream = new FileOutputStream(toExecfile); byte[] buffer = new byte[1024]; while (dis.available() > 0) { int bytesRead = dis.read(buffer); if (bytesRead == -1)break; fileoutStream.write(buffer, 0, bytesRead); } fileoutStream.flush(); fileoutStream.close(); System.out.println(getClass() + " Server>resiveFile=100%"); return toExecfile; } catch (FileNotFoundException e) { e.printStackTrace(); okErrorDialog("file for tmp scriptFolder not found!","ATT:File not found"); return null; } catch (IOException e) { okErrorDialog("file for tmp scriptFolder not found!","ATT:File not found"); e.printStackTrace(); return null; } finally { try { fileoutStream.close(); } catch (IOException e){e.printStackTrace();} } } //-------------------------------------------------------------------------------// public void okErrorDialog(String message, String title) { JOptionPane.showMessageDialog(null, message, title,JOptionPane.ERROR_MESSAGE); } //-------------------------------------------------------------------------------// private void sendDefaults() { try { dos.writeUTF("0"); dos.flush(); // sendOutputFile("0"); } catch (IOException e) { e.printStackTrace(); } } //-------------------------------------------------------------------------------// private synchronized void startServing() { try { serversocket = new ServerSocket(4711); System.out.println("****************SERVER IN SERVING MOD*********************"); System.out.println("Server is started...\nwait for client..."); socket = serversocket.accept(); dos = new DataOutputStream(socket.getOutputStream()); dis = new DataInputStream(socket.getInputStream()); } catch (IOException e) { System.out.println("Startserving failed"); e.printStackTrace(); closeConnection(); startServing(); } // while (socket.isBound()) { System.out.println("Server rececived Connection "); String reived; try { reived = dis.readUTF(); // if(reived.equals("q"))break; System.out.println("Received from client > " + reived); StringTokenizer st=new StringTokenizer(reived,","); if(st.countTokens()!=3) { sendDefaults(); } else { String filename=st.nextToken(); String cmd=st.nextToken(); String id=st.nextToken(); File f=receiveFile(filename); if(f==null) { sendDefaults();break; } if(f.exists()) { // int res=scriptexecuter.executeFile(f); int res=1; dos.writeUTF(""+1); if(res!=1) { sendDefaults(); } } else { sendDefaults(); } } } catch (IOException e) { e.printStackTrace(); closeConnection(); System.out.println(" Connection Closed ConnectionProblem whileSocket.bound!"); break; } System.out.println("Server send message"); System.out.println("***************SERVER HAS FINISHED wait for next File"); } startServing(); } //-------------------------------------------------------------------------------// public static void main(String args[]) { Thread t1=new Thread(new Runnable(){ public void run() { Server server=new Server(); server.startServing(); } }); t1.start(); //-------------------------------------------------------------------------------// } }
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
import java.io.*; import java.net.*; import java.util.Vector; import javax.swing.JFileChooser; import javax.swing.JOptionPane; public class Client { private Socket socket; private DataInputStream dis=null; private DataOutputStream dos=null; boolean connection; boolean streamsonline; Vector<File> caseFiles=null; private FileInputStream fileinputStream=null; private boolean connected; // -----------------------------------------------------------------------------OKERRORDIALOG------------ private void setcaseFiles(Vector<File> caseFiles){this.caseFiles=caseFiles;} // -----------------------------------------------------------------------------OKERRORDIALOG------------ private boolean connectStream() { try { dis=new DataInputStream(socket.getInputStream()); dos=new DataOutputStream(socket.getOutputStream()); connected=true; return true; } catch (IOException e) { System.err.println("Streams not initialized!!"); e.printStackTrace(); connected =false; return false; } } // -----------------------------------------------------------------------------OKERRORDIALOG------------ private boolean connect2Server() { try { socket=new Socket("localhost",4711); return true; } catch (UnknownHostException e) { System.err.println("UNKNOWN HOST localhost"); e.printStackTrace(); connected=false; return false; } catch (IOException e) { System.err.println("IOException connectClient localhost"); e.printStackTrace(); connected=false; return false; } } // -----------------------------------------------------------------------------OKERRORDIALOG------------ public void okErrorDialog(String message, String title) { JOptionPane.showMessageDialog(null, message, title,JOptionPane.ERROR_MESSAGE); } // -----------------------------------------------------------------------------OKERRORDIALOG------------ public boolean sendUTF(String s) { try { dos.writeUTF(s); dos.flush(); return true; } catch (IOException e) {e.printStackTrace();return false;} } // -----------------------------------------------------------------------------OKERRORDIALOG------------ private boolean send(File f, String caseID) { if (socket == null) { okErrorDialog("AClient is not connected.Please connect and try\nagain.","Connection failed"); return false; } if (f == null || !f.exists()) { okErrorDialog("One or more files for case doesnt exists!.\n caseID "+ caseID, "File not found"); return false; } System.out.println("sending File...." + f.getName()); byte[] buffer = new byte[16384]; try { fileinputStream = new FileInputStream(f); while (fileinputStream.available() > 0) { dos.write(buffer, 0, fileinputStream.read(buffer)); } dos.flush(); System.out.println("send!!"); return true; } catch (FileNotFoundException e) { System.out.println("FILENOTFOUND in sendFile"); e.printStackTrace(); return false; } catch (IOException e) { System.out.println("IO in sendFile"); e.printStackTrace(); return false; } finally { try { fileinputStream.close(); } catch (IOException e){e.printStackTrace();} } } //-----------------------------------------------------------------------------OKERRORDIALOG------------ private boolean sendInformation(String FileName, String cmd, String filecnt) { try { dos.writeUTF(FileName + "," + cmd + "," +filecnt); System.out.println("Client write information.....end"); dos.flush(); return true; } catch (IOException e) { System.out.println("Send Information Fehler"); e.printStackTrace(); return false; } } //-----------------------------------------------------------------------------OKERRORDIALOG------------ private synchronized boolean startProcedure() { boolean procedureOK=true; if(connection && streamsonline) { for(int i=0;i<caseFiles.size();i++) { if(procedureOK==false) { try { dos.writeUTF("q"); return false; } catch (IOException e) { e.printStackTrace(); } return false; } File actScript=caseFiles.get(i); if(actScript==null||!actScript.exists()) { procedureOK=false; try { dos.writeUTF("q"); } catch (IOException e) {e.printStackTrace();} break; } // if(!socket.isConnected()||socket.isClosed()) // { // System.out.println("Connection closed"); // try // { // dis.close(); // dos.close(); // procedureOK=false; // break; // } // catch (IOException e) // { // e.printStackTrace(); // procedureOK=false; // okErrorDialog("Client not connected", "Connection failed"); // break; // } // } System.out.println("**************CLIENT STARTED*******************"); if(!sendInformation(actScript.getName(), "cmd", "filecnt")) { procedureOK=false; try { dos.writeUTF("q"); } catch (IOException e) {e.printStackTrace();} break; } System.out.println("Client send message"); System.out.println("sending File"); if(!send(actScript, "1")){procedureOK=false;break;} System.out.println("CLIENT WAITING FOR SERVER ANSWER...."); try { String received=dis.readUTF(); if(received.equals("1"))procedureOK=true; else { System.out.println("failed Server Res= > "+received); procedureOK=false; } } catch (IOException e) { e.printStackTrace(); procedureOK=false; break; } System.out.println("END OF PROCEDURE FOR SCRIPT ="+actScript.getName()); System.out.println("PROCEDURE IS ="+procedureOK); } return procedureOK; } else { System.out.println("connection or streams not online"); return false; } } //-----------------------------------------------------------------------------OKERRORDIALOG------------ private boolean closeConnection() { try { if(dos!=null)dos.close(); if(dis!=null)dis.close(); if(socket!=null)socket.close(); System.out.println("Connection end"); return true; } catch (IOException e) { e.printStackTrace(); return false; } } //-----------------------------------------------------------------------------OKERRORDIALOG------------ public static void main(String args[]) { JFileChooser choos=new JFileChooser("."); Vector<File> v=new Vector<File>(); choos.showOpenDialog(null); v.add(choos.getSelectedFile()); final Client client=new Client(); client.connection= client.connect2Server(); client.streamsonline= client.connectStream(); client.setcaseFiles(v); // client.startProcedure(v); Thread t1=new Thread(new Runnable(){ @Override public void run() { for(int i=0;i<10;i++) { client.startProcedure(); } } }); //dies ist ein test um einen zweiten durchlauf zu testen t1.start(); try { Thread.sleep(20000); } catch (InterruptedException e) { e.printStackTrace(); } //----------------------------------------------------- //eigentlich soll die connection nur vom benutzter geclosed werden //solange das programm laeuft soll die funktion main immerwieder neue vectoren ubergeben und diese ausfuhren System.out.println("ENDE"); } }
-
Als erstes fällt auf das dein Client und Server zum Senden bzw. zum Empfangen unterschiedliche Puffer haben (16384 / 1024)!
Warum überträgst du die Dateien mittels Byte-Stream?
Schau mal hier: http://www.tutorials.de/forum/java/2...bertragen.html
Ich verstehe nicht warum der Client mehrere Threats startet aber die alle auf eine final zu greifen ist Merkwürdig!
Wenn du so viele Fehlerbehandlung machst ist es meist nicht schlecht eine eigen Fehlerklasse zu schreiben! Dann kannst du alle Fehler in diese Klasse umleiten und dort die Behandlung machen!
Der java.net.Socket bietet schon alle Funktionen wie verbinden, dies in einzelne Methoden zu machen ist meist Überflüssig (dadurch wird der Code auch wieder lesbarer)!
Die Verbindung könnte z.B. durch den Client Konstruktor erfolgen :
Für welchen Fachbereich ist die Arbeit?Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
Client(String server, int port, Vector<File> caseFiles) { this.caseFiles = caseFiles; try { socket = new Socket(server, port); dis = new DataInputStream(socket.getInputStream()); dos = new DataOutputStream(socket.getOutputStream()); connected = streamsonline = true; } catch (UnknownHostException e) { System.err.println("UNKNOWN HOST localhost"); e.printStackTrace(); connected = false; } catch (IOException e) { System.err.println("IOException in Client"); e.printStackTrace(); connected = false; } } public static void main(String args[]) { JFileChooser choos = new JFileChooser("."); Vector<File> v = new Vector<File>(); choos.showOpenDialog(null); v.add(choos.getSelectedFile()); Client client = new Client("localhost",4711, v); }
Das sind die Dinge die mir auffielen!
Gruß XeoX!Wenn du jemandem auf die Brille trittst, erinnere ihn: Man sieht nur mit dem Herzen gut.
(Antoine de Saint-Exupéry)
-
20.01.10 23:04 #6
- Registriert seit
- Jan 2010
- Beiträge
- 8
Hallo,
also ersteinmal danke für deine tips habe aber mein Problem heute entdeckt der fehler lag in einer anderen klasse in der etwas ausgeführt wurde dort hatte ich einen process nicht geschlossen und der Thread hat sich nicht beendet.
Der grund warum das alles so durcheinander ist der, das ich schon soviel daran herum probiert habe jetzt ist alles übersichtiger geworden
und vernünftig geordnet.
Danke für deine Hilfe Xeox.
Die thesis ist aus dem Fachbereich Softwaretechnick ist ein Umfangreiches programm dies ist nur eine funktionalität im Hauptprogramm.
Vielen Dank Xeox hoffe ich stöße nicht auf weitere fehler
-
Moin,
dann hätte ich ja lange suchen können!
Dann wünsche ich dir noch viel Spaß und Erfolg!
Maskierst du den Beitrag noch als erledigt!
Und gerne auch eine Bewertung!
XeoX!Wenn du jemandem auf die Brille trittst, erinnere ihn: Man sieht nur mit dem Herzen gut.
(Antoine de Saint-Exupéry)
Ähnliche Themen
-
Papier bleibt immer im Drucker stecken!
Von maxiw im Forum HardwareAntworten: 5Letzter Beitrag: 08.05.07, 19:18 -
WinXP Maus bleibt aller paar Sekunden Stecken
Von exitboy im Forum Microsoft WindowsAntworten: 4Letzter Beitrag: 06.05.06, 18:41 -
Suse Linux 10.0 bleibt bei Installation stecken
Von cesupa im Forum Linux & UnixAntworten: 6Letzter Beitrag: 07.12.05, 15:46 -
3D Studio Max bleibt stecken
Von trrt im Forum 3D Studio MaxAntworten: 4Letzter Beitrag: 08.05.05, 10:03 -
HILFE DVD überspielung bleibt stecken
Von smaragdamethist im Forum Videoschnitt, Videotechnik & -produktionAntworten: 0Letzter Beitrag: 24.01.05, 22:55





Zitieren
Login





