403-guruh talabasi Andaqulov Orifning Tarmoqni dasturlash fanidan 3-labaratorya ishi



Download 102,43 Kb.
bet2/2
Sana01.01.2022
Hajmi102,43 Kb.
#299338
1   2
Bog'liq
andaqulov3

Dastur kodi:

Server qismi:

package minorov;

import java.io.*;

import java.net.ServerSocket;

import java.net.Socket;

import java.util.ArrayList;
public class Server {

private static ServerSocket server;

public static void main(String args[]) {

try{

server = new ServerSocket(3232);

while (true){

System.out.println("Waiting for incoming connection");

Socket client = server.accept();

PrintWriter to_client=new PrintWriter(new OutputStreamWriter(client.getOutputStream()));

InputStream instream=(InputStream) client.getInputStream();

BufferedReader br = new BufferedReader(new InputStreamReader(instream));

DataInputStream in = new DataInputStream(instream);

System.out.println("Going to read data from buffered reader ");

String line= br.readLine();

System.out.println("Recedived:"+line);

String[] items=line.split(",");

ArrayList numbers=new ArrayList();

for (String item:items){

String[] tenglik=item.split("=");

numbers.add(Integer.parseInt(tenglik[1]));

}

String res=logic(numbers);



String response=res;

System.out.println("Natija1: "+response);

to_client.println("Natija2: "+response);

to_client.flush();

client.close();

}

}



catch(IOException e){

e.printStackTrace();

}

}

private static String logic(ArrayList numbers){



return "S= "+String.valueOf(numbers.get(0)*numbers.get(1))+" P= "+String.valueOf((numbers.get(0)+numbers.get(1))*2);

}

}



Klient uchun

package minorov;

import java.io.*;

import java.net.Socket;

import java.util.Scanner;

/**


* Created by shazzle on 4/18/16.

*/

public class Client {

public static void main(String args[]) {

Scanner scanner=new Scanner(System.in);

try{

Socket server = new Socket("localhost",3232);

PrintWriter to_server = new PrintWriter(new OutputStreamWriter(server.getOutputStream()));

InputStream instream = server.getInputStream();

BufferedReader br=new BufferedReader(new InputStreamReader(instream));

DataInputStream in=new DataInputStream(instream);

int a,b;

System.out.print("A-ni kiriting ");

a=scanner.nextInt();

System.out.print("B-ni kiriting ");

b=scanner.nextInt();

StringBuilder bdr=new StringBuilder();

bdr.append("a="+Integer.toString(a));

bdr.append(",");

bdr.append("b="+Integer.toString(b));

to_server.println(bdr.toString());

to_server.flush();

System.out.println(br.readLine());

}catch(IOException e){

e.printStackTrace();



}

}

}




Download 102,43 Kb.

Do'stlaringiz bilan baham:
1   2




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish