Terminology: A client or a server may use one or more network addresses.
A network address has two parts: the host address and the port number on
that host. The host address is an IP address, either specified or
obtained from the JVM. The port number is defined and agreed upon
by communicating programs. Read documentation of classes DatagramSocket,
MulticastSocket, DatagramPacket, and InetAddress in java.net.
Terminology: A multi-threaded program runs several threads at the
same time. Threads communicate directly with shared objects.
Read documentation of interface Runnable in java.lang.
A nice example using multicast and multi-threading
is provided by Prof. Amy Murphy. An
example using variable size messages is also available on-line.
-
Sever threads
-
A listener that listens to a multi-cast address. All groups must
use the same address, which is 230.0.0.200, and the same port number, which
is 2000. When hearing a client message, the listener replies with
a message, which contains its "sender identity" and the port entry to its
service provider (described next) in item "reply port". A client
can then send its request to the service provider thread. The client
request and all subsequently described messages are unicast messages.
The address of a unicast message is "host : port". A thread can find
its host by getLocalHost method and can find the host of a sender from
its message by DatagramPacket.getAddress method. The port number
is supplied in the "reply port" item in the message.
-
A service provider that waits a request message from a client. Upon
receiving the message, it will extract the item "hyper min-cut problem",
which will be an XML document describing a hyper-graph and two of its nodes.
It then invokes the solver program and obtains the minimum cut set.
It will then encode the cut set as another XML document, insert it as the
message item "hyper min-cut solution", and send the message to the requesting
client based on the "reply port" from the request message. It inserts
an "error message" item if the solver fails.
-
Client threads
-
A service finder that sends its address to the multicast port and collects
responses from available servers. It then provides them as choices
to the user interface, by which a user will select which server s/he wants
to use. It should update the list of available servers periodically.
-
A reqester that takes the hyper-graph document from the user interface,
sends it to the selected server, waits for a reply, and passes the reply
back to the user interface. A requester needs not to be an independent
thread. It can simply be functions of the user interface module.