/** * Fail Dklient.java * @author Jaanus Poial * @version 0.1 kevad 99 */ import java.net.*; import java.io.*; import java.applet.Applet; import java.util.Date; import java.awt.Graphics; public class Dklient extends Applet { // kliendipool on rakend InetAddress aadress; // serveri aadress int pordinumber; // suhtlemiseks kasutatav UDP-port public void init() { // Applet-klassi meetodi u"lekatmine try { aadress = InetAddress.getByName (getCodeBase().getHost()); if (getParameter ("port") == null) pordinumber = 5678; // suvaliselt valitud vaikeva"a"rtus else pordinumber = Integer.parseInt (getParameter ("port")); // pordinumber tuleb veebilehelt parameetrina } catch (UnknownHostException e) { // to"o"delda } } void saada (String teade) { try { byte [] andmed = teade.getBytes(); DatagramPacket pakett = new DatagramPacket (andmed, andmed.length, aadress, pordinumber); DatagramSocket dpistik = new DatagramSocket(); dpistik.send (pakett); dpistik.close(); } catch (IOException e) { // to"o"delda } } public void start() { // Applet-klassi meetodi u"lekatmine String s = " " + new Date().toString() + " " + System.getProperty ("os.name") + " " + System.getProperty ("os.version") + " " + System.getProperty ("os.arch") + "\n " + System.getProperty ("java.vendor"); saada (s); } public void stop() { // Applet-klassi meetodi u"lekatmine String s = " " + new Date().toString() + " lahkus lehelt"; saada (s); } public void paint (Graphics ekraan) { // Applet-klassi meetod ekraan.drawString ("Spioon" , 50, 25); } } // Dklient lopp