DataGram Applet in java
Objective:
Build an applet that sends a datagram to a
server each time that it is started or stopped. Further build a server
application that receives the sent datagram and prints it out
Packages used:
- java.net.* :Package used for coding in
network connections.
- java.applet.* :Package used while creating applet. Provides the classes necessary to create an applet and the
classes an applet uses to communicate with its applet context.
- java.awt.*; :Contains all of the classes for
creating user interfaces and for painting graphics and images.
- java.awt.event.*: Provides interfaces and
classes for dealing with different types of events fired by AWT
components.
Classes used:
·
DatagramSocket : This class represents a socket for sending and receiving
datagram packets.
·
DatagramPacket
: This class represents a
datagram packet.
Logical flow of the program:
·
Server is
created by DatagramSocket class.
·
When an
applet is started, inside the start() method object of DatagramPacket is
created. This object sends a message to server saying “Applet started”
·
When an
applet is stopped,inside the stop() method object of DatagramPacket is
created.This object sends a message to server saying “Applet stopped”.
Important notes:
1.
Open two
command prompts for client and server respectively.
2.
Server
side java code must be compiled and ececuted before compiling the client side
java code.
0 comments: