Tarmoqni dasturlash asoslari
Download 426,5 Kb.
|
TDA
- Bu sahifa navigatsiya:
- TCPServer.java
TCPClient.java
package abbos_ibragimov; import java.io.DataInputStream;
public class TCPClient { public static void main(String[] args) throws IOException { Socket socket = new Socket("localhost", 8080); DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream()); DataInputStream inputStream = new DataInputStream(socket.getInputStream()); Scanner scanner = new Scanner(System.in); System.out.print("Enter n: "); int n = scanner.nextInt(); StringBuilder data = new StringBuilder(); for (int i = 0; i < n; i++) { data.append(scanner.nextInt()).append("~"); } outputStream.writeUTF(data.toString()); String result = inputStream.readUTF();
socket.close(); inputStream.close(); outputStream.close(); }
TCPServer.java package abbos_ibragimov; import java.io.DataInputStream;
public class TCPServer { public static void main(String[] args) throws IOException { ServerSocket serverSocket = new ServerSocket(8080); Socket socket = serverSocket.accept(); if (socket.isConnected()) { System.out.println("tcp.Server ishga tushdi"); } DataInputStream inFromClient = new DataInputStream(socket.getInputStream()); DataOutputStream outFromClient = new DataOutputStream(socket.getOutputStream()); String data = inFromClient.readUTF(); String[] array = data.split("~");
for (int i = 0; i < array.length; i++) { try { int son = Integer.parseInt(array[i]); if (son > max) {
} catch (Exception e) { array = Arrays.copyOf(array, array.length - 1); } } outFromClient.writeUTF(String.valueOf((max))); socket.close(); serverSocket.close(); inFromClient.close(); outFromClient.close(); if (socket.isClosed()) { System.out.println("tcp.Server yopildi"); } }
TCP soketi asosida uchburchakning bissektrisa uzunligini hisoblash kliyent-server dasturini tuzing. Download 426,5 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling