... DatagramPacket(data,
45                         data.length, InetAddress.getLocalHost(), 5000);
46
47                      socket.send(sendPacket); // send packet
48                      displayArea.append("Packet sent\n");
49                      displayArea.setCaretPosition(
50                         displayArea.getText().length());
51                    }
52                    catch (IOException ioException)
53                    {
54                       displayMessage(ioException + "\n");
55                       ioException.printStackTrace();
56                    }
57                }
58            }
59       );
60
61       add(enterField, BorderLayout.NORTH);
62
63       displayArea = new JTextArea();
64       add(new JScrollPane(displayArea), BorderLayout.CENTER);
65
66       setSize(400, 300); // set window size
67       setVisible(true); // show window
68
69       try // create DatagramSocket for sending and receiving packets
70       {
71          socket = new DatagramSocket();
72       }
73       catch (SocketException socketException)
74       {
75 socketException.printStackTrace(); ...

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.