public static void main(String[] args) {
		int serverPort = 19999;
		if (args.length > 0) {
			serverPort = Integer.parseInt(args[0]);
		}
		Server server = new Server();
		TCServerSocket socket = null;
		TCSocket connection = null;
		try {
			socket = new TCServerSocketFactory(serverPort).open();
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}

		System.out.print("listening on port ");
		System.out.println(serverPort);

		while (true){
			try {
				connection = socket.accept();
				while(true){
					TCMessage message = connection.readPacket();
					System.out.print("Message received: ");
				
					if(message instanceof TCUploadRequestMessage) {
						connection.sendPacket(server.uploadFile((TCUploadRequestMessage) message));
					}
		
					if(message instanceof TCDownloadRequestMessage) {
						connection.sendPacket(server.downloadFile((TCDownloadRequestMessage) message));
					}
		
					if(message instanceof TCVouchRequestMessage) {
						connection.sendPacket(server.createVouch((TCVouchRequestMessage) message));
					}
		
					if(message instanceof TCListRequestMessage) {
						connection.sendPacket(server.listFiles((TCListRequestMessage) message));
					}
				}
			} catch (Exception ex) {
				System.out.println("Client disconnected.");
			}
		}
	}