Untitled
Untitled
Untitled
Your answer
Classmate answers
Selamawit Alemu
Server.java
import java.io.*;
import java.net.*;
try
Socket s=server.accept();
String str=(String)din.readUTF();
server.close();
catch(Exception e)
System.out.println(e);
}
Client.java
import java.io.*;
import java.net.*;
try
dout.flush();
dout.close();
s.close();
catch(Exception e)
System.out.println(e);
2. using DatagramSocket
import java.io.*;
import java.net.*;
class UDPServer
dp = new DatagramPacket(buf,buf.length);
(new InputStreamReader(System.in));
ia = InetAddress.getLocalHost();
System.out.println("Server is Running...");
while(true)
serversocket.receive(dp);
if(str.equals("Chaw"))
System.out.println("Terminated..");
break;
}
System.out.println("Client Message: " + str);
buf = str1.getBytes();
import java.io.*;
import java.net.*;
class UDPClient
InputStreamReader(System.in));
ia = InetAddress.getLocalHost();
System.out.println("Client is saying Chaw");
while(true)
buf = str.getBytes();
if(str.equals("Chaw"))
System.out.println("Terminated...");
clientsocket.send(newDatagramPacket(buf,str.length(), ia,sport));
break;
clientsocket.receive(dp);
Melese Alemante9:35 AM
Great!.