Client
import java.io.*;
import java.net.*;
class ptb2_client{
public static void main(String[] args) throws IOException
{
DatagramSocket clientSocket=new DatagramSocket();
InetAddress IPAddress=InetAddress.getByName("THANGNH-1989");
BufferedReader inFromUser=new BufferedReader(new InputStreamReader(System.in));
double a;
do{
System.out.print("nhap so a:");
a=Double.parseDouble(inFromUser.readLine());
if(a==0)
System.out.print("phai nhap a khac 0");
}while(a==0);
System.out.print("nhap so b:");
double b=Double.parseDouble(inFromUser.readLine());
System.out.print("nhap so c:");
double c=Double.parseDouble(inFromUser.readLine());
byte[] sendData=new byte[1024];
sendData=String.valueOf(a).getBytes();
DatagramPacket sendPacket=new DatagramPacket(sendData,sendData.length,IPAddress,6789);
clientSocket.send(sendPacket);
sendData=String.valueOf(b).getBytes();
sendPacket.setData(sendData);
sendPacket.setLength(sendData.length);
clientSocket.send(sendPacket);
sendData=String.valueOf(c).getBytes();
sendPacket.setData(sendData);
sendPacket.setLength(sendData.length);
clientSocket.send(sendPacket);
byte [] receiveData=new byte [1024];
DatagramPacket receivePacket=new DatagramPacket(receiveData,receiveData.length);
clientSocket.receive(receivePacket);
String f=new String(receivePacket.getData());
System.out.print(f);
clientSocket.close();
}
}
Bạn đang đọc truyện trên: Truyen247.Pro