added FileServer class

git-svn-id: svn://anubis/gvsu@31 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
josh 2008-03-08 20:01:06 +00:00
parent 51a57271b3
commit aef571e8be
4 changed files with 91 additions and 24 deletions

View File

@ -0,0 +1,51 @@
import java.io.*;
import java.net.*;
import java.util.*;
public class FileServer implements Runnable
{
private int m_port;
private String m_rootPath;
private ServerSocket m_serverSocket;
public FileServer(int port, String rootPath)
{
m_port = port;
m_rootPath = rootPath;
}
public void run()
{
try {
m_serverSocket = new ServerSocket(m_port);
/* porcess connection requests */
for (;;)
{
Socket clientSocket = m_serverSocket.accept();
Thread thread = new Thread(new FileHandler(clientSocket));
thread.start();
}
} catch (IOException ioe) {
System.out.println("KaZaClient: IO Exception!");
ioe.printStackTrace();
return;
}
}
private class FileHandler implements Runnable
{
private Socket m_socket;
public FileHandler(Socket socket)
{
m_socket = socket;
}
public void run()
{
}
}
}

View File

@ -1,10 +1,17 @@
import java.io.*;
import java.net.*;
import java.util.*;
public class KaZaClient public class KaZaClient
{ {
private String m_sharedFolder;
public static final int LISTEN_PORT = 3443; public static final int LISTEN_PORT = 3443;
public KaZaClient(String userName, int kbps, public KaZaClient(String userName, int kbps,
String sharedFolder, String server) String sharedFolder, String server)
{ {
m_sharedFolder = sharedFolder;
Thread fsThread = new Thread(new FileServer(LISTEN_PORT, m_sharedFolder));
} }
} }

View File

@ -6,19 +6,25 @@ import java.util.*;
public class KaZaGUI extends JFrame public class KaZaGUI extends JFrame
{ {
private JButton m_browseButton;
private JButton m_connectButton;
private JButton m_closeButton;
private JTextField m_userNameField;
private JTextField m_shareFolderField;
private JTextField m_statusField;
private JTextField m_serverField;
private ActionEventHandler m_handler; private ActionEventHandler m_handler;
private JComboBox m_speedCombo;
private KaZaClient m_client; private KaZaClient m_client;
private KaZaServer m_server; private KaZaServer m_server;
private Thread m_serverThread; private Thread m_serverThread;
private JTextField m_serverStatusField;
/* client tab components */
private JButton m_browseButton;
private JButton m_connectButton;
private JButton m_closeButton;
private JButton m_searchButton;
private JTextField m_userNameField;
private JTextField m_shareFolderField;
private JLabel m_statusLabel;
private JTextField m_serverNameField;
private JTextField m_queryField;
private JComboBox m_speedCombo;
/* server tab components */
private JLabel m_serverStatusLabel;
private JButton m_serverStartButton; private JButton m_serverStartButton;
public KaZaGUI() public KaZaGUI()
@ -73,7 +79,7 @@ public class KaZaGUI extends JFrame
m_client = new KaZaClient(m_userNameField.getText(), m_client = new KaZaClient(m_userNameField.getText(),
cs.getKbps(), cs.getKbps(),
m_shareFolderField.getText(), m_shareFolderField.getText(),
m_serverField.getText()); m_serverNameField.getText());
} }
else if (e.getSource() == m_serverStartButton) else if (e.getSource() == m_serverStartButton)
{ {
@ -105,12 +111,14 @@ public class KaZaGUI extends JFrame
m_shareFolderField = new JTextField(); m_shareFolderField = new JTextField();
m_browseButton = new JButton("..."); m_browseButton = new JButton("...");
m_browseButton.addActionListener(m_handler); m_browseButton.addActionListener(m_handler);
m_serverField = new JTextField(); m_serverNameField = new JTextField();
m_statusField = new JTextField(); m_statusLabel = new JLabel();
m_connectButton = new JButton("Connect"); m_connectButton = new JButton("Connect");
m_connectButton.addActionListener(m_handler); m_connectButton.addActionListener(m_handler);
m_closeButton = new JButton("Close"); m_closeButton = new JButton("Close");
m_closeButton.addActionListener(m_handler); m_closeButton.addActionListener(m_handler);
m_searchButton = new JButton("Search");
m_searchButton.addActionListener(m_handler);
Vector<ConnectionSpeed> speeds = new Vector<ConnectionSpeed>(); Vector<ConnectionSpeed> speeds = new Vector<ConnectionSpeed>();
speeds.add(new ConnectionSpeed("Modem", 50)); speeds.add(new ConnectionSpeed("Modem", 50));
speeds.add(new ConnectionSpeed("768 Kbps", 768)); speeds.add(new ConnectionSpeed("768 Kbps", 768));
@ -125,6 +133,7 @@ public class KaZaGUI extends JFrame
m_speedCombo = new JComboBox(speeds); m_speedCombo = new JComboBox(speeds);
m_speedCombo.setSelectedIndex(3); m_speedCombo.setSelectedIndex(3);
m_userNameField = new JTextField(); m_userNameField = new JTextField();
m_queryField = new JTextField();
JPanel clientPanel = new JPanel(); JPanel clientPanel = new JPanel();
clientPanel.setLayout(new BoxLayout(clientPanel, BoxLayout.Y_AXIS)); clientPanel.setLayout(new BoxLayout(clientPanel, BoxLayout.Y_AXIS));
@ -147,7 +156,13 @@ public class KaZaGUI extends JFrame
p = new JPanel(); p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
p.add(new JLabel("Server: ")); p.add(new JLabel("Server: "));
p.add(m_serverField); p.add(m_serverNameField);
clientPanel.add(p);
p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
p.add(new JLabel("Search query: "));
p.add(m_queryField);
p.add(m_searchButton);
clientPanel.add(p); clientPanel.add(p);
clientPanel.add(new Box.Filler(new Dimension(0, 0), clientPanel.add(new Box.Filler(new Dimension(0, 0),
new Dimension(0, Short.MAX_VALUE), new Dimension(0, Short.MAX_VALUE),
@ -155,7 +170,7 @@ public class KaZaGUI extends JFrame
Short.MAX_VALUE))); Short.MAX_VALUE)));
p = new JPanel(); p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
p.add(m_statusField); p.add(m_statusLabel);
p.add(new Box.Filler(new Dimension(0, 0), p.add(new Box.Filler(new Dimension(0, 0),
new Dimension(Short.MAX_VALUE, 0), new Dimension(Short.MAX_VALUE, 0),
new Dimension(Short.MAX_VALUE, Short.MAX_VALUE))); new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)));
@ -182,8 +197,8 @@ public class KaZaGUI extends JFrame
private JPanel getServerPanel() private JPanel getServerPanel()
{ {
m_serverStatusField = new JTextField(); m_serverStatusLabel = new JLabel();
m_serverStartButton = new JButton("Start Server"); m_serverStartButton = new JButton("Start MNH Server");
m_serverStartButton.addActionListener(m_handler); m_serverStartButton.addActionListener(m_handler);
JPanel serverPanel = new JPanel(); JPanel serverPanel = new JPanel();
@ -200,7 +215,7 @@ public class KaZaGUI extends JFrame
Short.MAX_VALUE))); Short.MAX_VALUE)));
p = new JPanel(); p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
p.add(m_serverStatusField); p.add(m_serverStatusLabel);
p.add(new Box.Filler(new Dimension(0, 0), p.add(new Box.Filler(new Dimension(0, 0),
new Dimension(Short.MAX_VALUE, 0), new Dimension(Short.MAX_VALUE, 0),
new Dimension(Short.MAX_VALUE, Short.MAX_VALUE))); new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)));

View File

@ -8,14 +8,8 @@ public class KaZaServer implements Runnable
public static final int LISTEN_PORT = 3442; public static final int LISTEN_PORT = 3442;
private ServerSocket m_serverSocket; private ServerSocket m_serverSocket;
public KaZaServer()
{
System.out.println("KaZaServer was created");
}
public void run() public void run()
{ {
System.out.println("Listening on " + LISTEN_PORT);
try { try {
m_serverSocket = new ServerSocket(LISTEN_PORT); m_serverSocket = new ServerSocket(LISTEN_PORT);
@ -28,7 +22,7 @@ public class KaZaServer implements Runnable
thread.start(); thread.start();
} }
} catch (IOException ioe) { } catch (IOException ioe) {
System.out.println("IO Exception!"); System.out.println("KaZaServer: IO Exception!");
ioe.printStackTrace(); ioe.printStackTrace();
return; return;
} }