diff --git a/ws2012/P2P/uebungen/2/p2p_ex2/src/buffered/BufferedNetworkStackClient.java b/ws2012/P2P/uebungen/2/p2p_ex2/src/buffered/BufferedNetworkStackClient.java index 46a17232..f4cdc60d 100644 --- a/ws2012/P2P/uebungen/2/p2p_ex2/src/buffered/BufferedNetworkStackClient.java +++ b/ws2012/P2P/uebungen/2/p2p_ex2/src/buffered/BufferedNetworkStackClient.java @@ -93,7 +93,12 @@ public class BufferedNetworkStackClient { return "pop"; } - public void print() { + public void print(String host, int port) throws IOException { + if (channel == null) { + channel = DatagramChannel.open(); + } + InetSocketAddress dest = new InetSocketAddress(host, port); + channel.send(ByteBuffer.wrap(new byte[] { CMD_PRINT }), dest); } } diff --git a/ws2012/P2P/uebungen/2/p2p_ex2/src/buffered/ClientGUI.java b/ws2012/P2P/uebungen/2/p2p_ex2/src/buffered/ClientGUI.java index b581bc3e..ea1e90ee 100644 --- a/ws2012/P2P/uebungen/2/p2p_ex2/src/buffered/ClientGUI.java +++ b/ws2012/P2P/uebungen/2/p2p_ex2/src/buffered/ClientGUI.java @@ -22,7 +22,6 @@ public class ClientGUI extends JFrame { private JTextField userinput; private JTextField txtPort; private JScrollPane scrollPane; - // private int port; private JTextPane textPane; private BufferedNetworkStackClient client = null; private JTextField txtHost; @@ -47,6 +46,7 @@ public class ClientGUI extends JFrame { * Create the frame. */ public ClientGUI() { + setResizable(false); client = new BufferedNetworkStackClient(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -58,7 +58,7 @@ public class ClientGUI extends JFrame { JPanel panelPref = new JPanel(); contentPane.add(panelPref, BorderLayout.NORTH); - panelPref.setLayout(new GridLayout(2, 4, 0, 0)); + panelPref.setLayout(new GridLayout(0, 4, 0, 0)); JLabel lblHost = new JLabel("Hostname:"); panelPref.add(lblHost); @@ -89,6 +89,21 @@ public class ClientGUI extends JFrame { JButton btnPop = new JButton("Pop"); panelPref.add(btnPop); + + JButton btnPrint = new JButton("Print"); + btnPrint.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + try { + client.print(txtHost.getText(), + Integer.valueOf(txtPort.getText())); + } catch (NumberFormatException e1) { + e1.printStackTrace(); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + }); + panelPref.add(btnPrint); btnPop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String received = "";