O‘ZBEKISTON RESPUBLIKASI AXBOROT TEXNOLOGIYALARI VA KOMMUNIKATSIYALARINI RIVOJLANTIRISH VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
4 Laboratoriya ishi
Mavzu: Telekommunikatsiya klient-server nazariyasi asosida aloqa tizimlari dasturlarini loyihalash va yaratish
Bajardi:TDS001u/2 guruh
Talabasi:Gapparov SH
Tekshirdi:Zarmasov E
4–Laboratoriya ishi: Telekommunikatsiya klient-server nazariyasi asosida aloqa tizimlari dasturlarini loyihalash va yaratish
Ishdan maqsad: Telekommunikatsiya klient-server nazariyasi va qo‘llanilish sharoitlari bilan tanishish. Aloqa tizimlarida klient va server qismlarining asosiy farqlari va vazifalarini o‘rganish.
Ishni bajarish tartibi:
Kodni kiritamiz client bilan serverni yaratamiz
Kiritilgan kodni korinishi
package lab4tds;
import java.io.*;
import java.net.*;
class server
{
public static void main(String argv[]) throws Exception
{
String qandaydirMatn;
String qayta_Ishlangan_Matn;
ServerSocket welcomeSocket = new ServerSocket(6789);
System.out.println("Server ishga tushdi!");
System.out.println("Kliyentdan so'rovni kutmoqda...");
while(true)
{
Socket connectionSocket = welcomeSocket.accept(); //so'rovni kutish
System.out.println("Kliyent server bilan bog'landi");
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
qandaydirMatn = inFromClient.readLine();
System.out.println("Server kliyentdan so'rovni qabul qildi");
System.out.println("Kliyentdan qabul qilingan matn: "+qandaydirMatn);
qayta_Ishlangan_Matn = qandaydirMatn.toUpperCase() + '\n';
outToClient.writeBytes(qayta_Ishlangan_Matn);
System.out.println("Server qabul qilingan so'rovni qayta ishlab kliyentga jo'natdi");
System.out.println("Qayta ishlangan matn: " +qayta_Ishlangan_Matn);
}
}
}
class client {
public static void main(String argv[]) throws Exception
{
String qandaydirMatn;
String qayta_Ishlangan_Matn;
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Kliyent ishga tushdi!!!");
Socket clientSocket = new Socket("localhost", 6789);
System.out.println("Kliyent server bilan bog'landi");
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
System.out.println("Serverga jo'natsh uchun ixtiyoriy matnni kiriting:");
qandaydirMatn = inFromUser.readLine();
outToServer.writeBytes(qandaydirMatn + '\n');
System.out.println("Kiritilgan matn serverga jo'natildi");
qayta_Ishlangan_Matn = inFromServer.readLine();
System.out.println("Qayta ishlangan matn serverdan keldi: " + qayta_Ishlangan_Matn);
clientSocket.close();
//System.out.println("Kliyent soketi yopildi!");
}
}
Natija
Do'stlaringiz bilan baham: |