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.


import java.io.Console;
import java.net.*;
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];

while(true)
{
ii) Create space for received datagram

______________________________________________________________________________________________________________________
serverSocket.receive(receivePacket);
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
_______________________________________________

serverSocket.send(sendPacket);
}
}
}
b) Create a snippet connect to a server name "myserver.org" 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.

You might also like