Salve a tutti, ho una domanda su un sorgente che ho scaricato dalla rete:

client:

import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.rmi.Naming;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

interface RemoteMetod extends Remote {
void writefile(Vector text, String name) throws RemoteException;
}

class ClientWriter extends UnicastRemoteObject implements RemoteMetod {

public ClientWriter() throws RemoteException {
}

public void writefile(Vector text, String name) {
try {
Object[] texti = text.toArray();
FileOutputStream fos = new FileOutputStream(name);
for(int i = 0; i < texti.length; i++) {
fos.write(Integer.parseInt(texti[i].toString()));
}
JOptionPane.showMessageDialog(null, "Ricevuto file", "Ricevuto", JOptionPane.INFORMATION_MESSAGE);
} catch(Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage(), "Errore", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
}
}

/**
* @author Matteo Tomasulo(netarrow)
*/
public class FileSender extends JFrame implements Runnable {
private Thread send;
private JTextField textField;
private String name;
private Vector text;

public static void main(String args[]) {
FileSender frame = new FileSender();
frame.setBounds(100, 100, 404, 116);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.show();
}
public FileSender() {
super();
getContentPane().setLayout(null);
{
final JPanel panel = new JPanel();
panel.setBounds(42, 9, 127, 26);
getContentPane().add(panel);
{
final JLabel label = new JLabel();
panel.add(label);
label.setText("Inserire file da inviare");
}
}
{
final JPanel panel = new JPanel();
panel.setBounds(174, 5, 182, 35);
getContentPane().add(panel);
{
final JTextField textField = new JTextField();
textField.setPreferredSize(new Dimension(100, 20));
panel.add(textField);

final JFrame parent = this;

final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FileDialog fd = new FileDialog(parent);
fd.setVisible(true);
if(!fd.getDirectory().equals("null") && !fd.getFile().equals("null")) {
textField.setText(fd.getDirectory() + fd.getFile());
name = fd.getFile();
reader.start();
}
}

Thread reader = new Thread(new Runnable() {
public void run() {
Vector v = new Vector();
try {
File file = new File(textField.getText());
FileInputStream fis = new FileInputStream(file);
int i = 0;
while((i = fis.read()) != -1) {
v.add(new Integer(i));
}
fis.close();
} catch(Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage(), "Errore", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
text = v;
}
});
});
panel.add(button);
button.setText("Cerca");
}
}
{
final JLabel label = new JLabel();
label.setHorizontalAlignment(SwingConstants.CENTER );
label.setBounds(50, 40, 120, 25);
getContentPane().add(label);
label.setText("Inserire ip");
}
{
textField = new JTextField();
textField.setBounds(180, 45, 100, 20);
getContentPane().add(textField);
}
{
final JButton button = new JButton();
button.setBounds(285, 40, 65, 25);
getContentPane().add(button);
button.setText("Invia");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
send.start();
}
});
}
setTitle("FileSender");
setResizable(false);
send = new Thread(this);
}


public void run() {
try {
String url = "rmi://" + textField.getText() + "/Server";
RemoteMetod cw = (RemoteMetod) Naming.lookup(url);
cw.writefile(text, name);
JOptionPane.showMessageDialog(null, "File inviato", "Inviato", JOptionPane.INFORMATION_MESSAGE);
} catch(Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage(), "Errore", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
}
}



Server:

import java.rmi.Naming;

import javax.swing.JOptionPane;

class Server {

public static void main(String args[]) {
try {
System.out.print("Eseguendo rmiregistry...");
Runtime r = Runtime.getRuntime();
r.exec("rmiregistry");
Thread.sleep(1500);
System.out.println("ok");
ClientWriter rm = new ClientWriter();
Naming.rebind("Server", rm);
System.out.println("Server in ascolto");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage(), "Errore", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
}
}


Come faccio ad indicare la porta da utilizzare per questo programma?