Server Class
Class Server
(Fig. 28.7) declares two DatagramPackets that the server uses to send and receive information and one DatagramSocket that sends and receives the packets. The constructor (lines 19–37), which is called from main
(Fig. 28.8, lines 7–12), creates the GUI in which the packets of information will be displayed. Line 30 creates the DatagramSocket
in a try
block. Line 30 in Fig. 28.7 uses the DatagramSocket
constructor that takes an integer port-number argument (5000
in this example) to bind the server to a port where it can receive packets from clients. Client
s sending packets to this Server
specify the same port number in the packets they send. A SocketException is thrown if the DatagramSocket
constructor fails to bind the ...
Get Java™ How To Program (Early Objects), Tenth 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.