Muhammad al-xorazmiy nomidagi toshkent axborot texnologiyalari universiteti telekommunikatsiya texnologiyalari


-variant Topshiriq: Ixtiyoriy konus sirti yuzini topish



Yüklə 31,01 Kb.
səhifə2/3
tarix16.12.2023
ölçüsü31,01 Kb.
#180991
1   2   3
abdumalik2-labarataotiya

2-variant

Topshiriq: Ixtiyoriy konus sirti yuzini topish

import java.io.IOException;

import java.net.DatagramPacket;

import java.net.DatagramSocket;

import java.net.InetAddress;


public class UDPServer2 {


public static void main(String[] args) throws IOException {


DatagramSocket serverSocket = new DatagramSocket(1234);

byte[] receiveData1 = new byte[1024];

byte[] receiveData2 = new byte[1024];

byte[] sendData;

System.out.println("Server ishga tushdi!");

while (true) {

DatagramPacket receivePacket1 = new

DatagramPacket(receiveData1, receiveData1.length);

serverSocket.receive(receivePacket1);

DatagramPacket receivePacket2 = new

DatagramPacket(receiveData2, receiveData2.length);

serverSocket.receive(receivePacket2);

InetAddress IPAddress = receivePacket1.getAddress();

int port = receivePacket1.getPort();

String l = new String(receivePacket1.getData(), 0, receivePacket1.getLength());

String r = new String(receivePacket2.getData(), 0, receivePacket2.getLength());

double area = Math.PI*Double.parseDouble(r)*(Double.parseDouble(l) + Double.parseDouble(r));

System.out.println("Qabul qilindi: " + l);

System.out.println("Qabul qilindi: " + r);

sendData = String.valueOf(area).getBytes();

DatagramPacket sendPacket =

new DatagramPacket(sendData, sendData.length, IPAddress,

port);

serverSocket.send(sendPacket);



}

}

}

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.net.DatagramPacket;

import java.net.DatagramSocket;

import java.net.InetAddress;


public class UDPClient2 {


Yüklə 31,01 Kb.

Dostları ilə paylaş:
1   2   3




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin