|
System.out.println("Server ishga tushdi...")
|
bet | 5/8 | Sana | 18.05.2024 | Hajmi | 0,9 Mb. | | #242341 |
Bog'liq 7ish00 System.out.println("Server ishga tushdi..."); while (true) { try (Socket clientSocket = serverSocket.accept()) { System.out.println("Klient ulandi...");
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);
double yuza = (d1 * d2) / 2;
PrintWriter output = new PrintWriter(clientSocket.getOutputStream(), true); output.println(yuza); System.out.println("Rombning yuzasi: " + yuza + " klientga yuborildi."); } } } } }
`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.
|
| |