You are on page 1of 2

(a) Create a Java codes based on algorithms below in the following coding.

Bina kod Java berdasarkan algorithm di dalam aturcara berikut.

class UDPServer {
public static void main(String args[]) throws Exception
i) Create datagram socket at port 9876
byte[ ] receiveData = new byte[1024];
byte[ ] sendData = new byte[1024];

ii) Create space for received datagram

String sentence = new String(receivePacket.getData( ));

iii) Get IP address port #, of sender

String capitalizedSentence = sentence.toUpperCase( );
sendData = capitalizedSentence.getBytes( );

iv) Create datagram to send to client

b) Create a snippet connect to a server name "" on port 2222 and display the
date of the server sends. The data is based on String data type. Build it only within try
and catch block. If theres exception occur, it will return the current client date.