• // Klientga yuzani yuborish
  • 1. `java.net.*` paketining klass va metodlari
  • - **`Socket`**: - `Socket(String host, int port)`
  • - `openConnection()` - `openStream()`
  • System.out.println("Server ishga tushdi...")




    Download 0,9 Mb.
    bet5/8
    Sana18.05.2024
    Hajmi0,9 Mb.
    #242341
    1   2   3   4   5   6   7   8
    Bog'liq
    7ish00

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

    while (true) {

    try (Socket clientSocket = serverSocket.accept()) {

    System.out.println("Klient ulandi...");


    // Klientdan diagonallarni qabul qilish

    BufferedReader input = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

    double d1 = Double.parseDouble(input.readLine());

    double d2 = Double.parseDouble(input.readLine());

    System.out.println("Qabul qilingan diagonallar: d1 = " + d1 + ", d2 = " + d2);


    // Rombning yuzasini hisoblash

    double yuza = (d1 * d2) / 2;


    // Klientga yuzani yuborish

    PrintWriter output = new PrintWriter(clientSocket.getOutputStream(), true);

    output.println(yuza);

    System.out.println("Rombning yuzasi: " + yuza + " klientga yuborildi.");

    }

    }

    }

    }

    }








    ### 1. `java.net.*` paketining klass va metodlari


    `java.net` paketi tarmoqli dasturlarni yozish uchun ishlatiladigan klasslarni o'z ichiga oladi. Quyida eng ko'p ishlatiladigan klasslar va ularning ba'zi metodlari keltirilgan:


    #### Klasslar:

    - **`Socket`**:

    - `Socket(String host, int port)`

    - `getInputStream()`

    - `getOutputStream()`

    - `close()`

    - **`ServerSocket`**:

    - `ServerSocket(int port)`

    - `accept()`

    - `close()`

    - **`URL`**:

    - `URL(String spec)`

    - `openConnection()`

    - `openStream()`

    - **`HttpURLConnection`**:

    - `connect()`

    - `disconnect()`

    - `getInputStream()`

    - `getResponseCode()`


    #### Metodlar:

    - `Socket` va `ServerSocket` klasslarining `getInputStream()` va `getOutputStream()` metodlari tarmoq orqali ma'lumot oqimlarini o'qish va yozish imkonini beradi.


    Download 0,9 Mb.
    1   2   3   4   5   6   7   8




    Download 0,9 Mb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



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

    Download 0,9 Mb.