Skip to content
Snippets Groups Projects
Select Git revision
  • 70dccd94c091c8cede88309370e3b2388f19e3d7
  • officialWithoutB default protected
  • masterWithoutB
  • master
  • masterWithoutV2
  • withoutbit
  • feature/Bot
7 results

FirstPage.java

Blame
  • ClientMain.java 2.98 KiB
    import java.io.File;
    import java.io.IOException;
    
    public class ClientMain {
    	
    	public static void main(String[] args) {
    		
    		int cport = -1;
    		int timeout = -1;
    		try {
    			// parse arguments
    			cport = Integer.parseInt(args[0]);
    			timeout = Integer.parseInt(args[1]);
    		} catch (NumberFormatException e) {
    			System.err.println("Error parsing arguments: " + e.getMessage());
    			System.err.println("Expected: java ClientMain cport timeout");
    			System.exit(-1);
    		}
    			
    		File downloadFolder = new File("downloads");
    		if (!downloadFolder.exists())
    			if (!downloadFolder.mkdir()) throw new RuntimeException("Cannot create download folder (folder absolute path: " + downloadFolder.getAbsolutePath() + ")");
    		
    		testClient(cport, timeout, downloadFolder);
    		
    		// example to launch a number of concurrent clients, each doing the same operations
    		/*for (int i = 0; i < 10; i++) {
    			new Thread() {
    				public void run() {
    					testClient(cport, timeout, downloadFolder);
    				}
    			}.start();
    		}*/
    	}
    	
    	public static void testClient(int cport, int timeout, File downloadFolder) {
    		Client client = null;
    		
    		try {
    			client = new Client(cport, timeout, Logger.LoggingType.ON_FILE_AND_TERMINAL);
    		
    			try { client.connect(); } catch(IOException e) { e.printStackTrace(); return; }
    			
    			String[] files = {"AllStar.txt", "Unknown.txt", "PumpkinHill.txt", "SnowHalation.txt", "Grandad.txt"};
    			
    			for(String file : files) {
    				try { client.store(new File(file)); Thread.sleep(500);} 
    				catch(IOException e) { e.printStackTrace(); }
    				catch(InterruptedException e) {e.printStackTrace();}
    			}
    			
    			/*
    			
    			try { list(client); } catch(IOException e) { e.printStackTrace(); }
    			
    			try { client.store(new File("AllStar.txt")); } catch(IOException e) { e.printStackTrace(); }
    			
    			try { client.store(new File("AllStar.txt")); } catch(IOException e) { e.printStackTrace(); }
    
    			try { client.store(new File("Unknown.txt")); } catch(IOException e) { e.printStackTrace(); }
    			
    			*/
    			String list[] = null;
    			try { list = list(client); } catch(IOException e) { e.printStackTrace(); }
    			
    			if (list != null)
    				for (String filename : list)
    					try { client.load(filename, downloadFolder); } catch(IOException e) { e.printStackTrace(); }
    			/*
    			if (list != null)