O`zbekiston respublikasi raqamli texnologiyalar vazirligi muhammad al-xorazmiy nomidagi toshkent axborot texnologiyalari universiteti


Download 296.57 Kb.
bet5/6
Sana18.06.2023
Hajmi296.57 Kb.
#1596483
1   2   3   4   5   6
Bog'liq
Individual Loyiha ishi.11

Ishning amaliy qismi.

Tizimni ishga tushirish uchun quyidagi amallar turli buyruq satrlarida yoki terminallarda bajarilishi kerak. Serverni ishga tushirish uchun Localhost kerak.


1) Proxy Localhost-ni standart port 9090-da ishga tushiring.
2) Serverni ishga tushiring
3) Mijozlarni ishga tushiring.
Yuqoridagi amallar uchun buyruqlar quyidagilardir:
localhost-->python3 -m Pyro4.naming-ni ishga tushiring
Serverni ishga tushiring--> python3 Server.py
Mijozni ishga tushiring--> python3 Client.py
Mijoz serverni to'g'ri joylashishini ta'minlash uchun, u Java'da RMI registrida ro'yxatdan o'tganga o'xshab nomlanishi va localhostda ro'yxatdan o'tkazilishi kerak. Bu quyidagi ko'rsatmalar yordamida amalga oshiriladi:
url = daemon.register(Server)
ns.register("RMI.calculator", url)
Server RMI.calculator deb nomlangan va u demon registrida ro'yxatdan o'tgan. Mijoz Serverni quyidagi kod yordamida topadi:
Client = Pyro4.Proxy("PYRONAME:RMI.calculator")
Endi Mijoz o'zgaruvchisi Mijoz ob'ekti sifatida ishlaydi. Ushbu ob'ekt endi serverda belgilangan usullarni chaqirishi va mijozdan istalgan parametrlarni qabul qilishi mumkin.

A. Server kodi:
import Pyro4
import random
import os
import datetime
import subprocess
now=datetime.datetime.now()
print('date: '+now.strftime('%d-%m-%y')+' Time:
'+now.strftime('%H:%M:%S'))
@Pyro4.expose
class Server(object):
def get_usid(self, name):
return "Hello, {0}.\n" \
"Your Current User Session is {1}:".format(name,
random.randint(0,1000))
def add(self, a, b):
return "{0} + {1} = {2}".format(a, b, a+b)
def subtract(self, a, b):
return "{0} - {1} = {2}".format(a, b, a-b)
def multiply(self, a, b):
return "{0} * {1} = {2}".format(a, b, a*b)
def division(self, a, b):
return "{0} / {1} = {2}".format(a, b, a/b)
def exp(self, a):
return "{0} ** {1} = {2}".format(a, a, a**a)
daemon = Pyro4.Daemon()
ns = Pyro4.locateNS()
url = daemon.register(Server)
ns.register("RMI.calculator", url)
print("The Server is now active., please request your
calculations or start file transfer")
daemon.requestLoop()


B. Mijoz kodi:

import Pyro4


import os
import datetime
Client = Pyro4.Proxy("PYRONAME:RMI.calculator")
name =input("What is your name? ").strip()
now=datetime.datetime.now()
print('date: '+now.strftime('%d-%m-%y')+' Time:
'+now.strftime('%H:%M:%S'))
print(Client.get_usid(name))
print("Enter the number of calculations to be done")
n=int(input("Enter n: "))
while (n>0):
n=n-1
a =int(input("Enter a: "))
b =int(input("Enter b: "))
print("Enter number for desired calculations: \n" +'1.ADD \n'+
'2.SUBTRACT \n'+ '3.MULTIPLY \n'+ '4.DIVISION \n'+
'5.EXPONENTIATION \n')
c=int(input('Enter your choice: '))
if (c==1):
print(Client.add(a,b))
elif (c==2):
print(Client.subtract(a,b))
elif (c==3):
print(Client.multiply(a,b))
elif (c==4):
print(Client.division(a,b))
elif (c==5):
print(Client.exp(a))
else:
print('invalid input')
Quyida ko'rsatilgan raqamlar yuqorida aytib o'tilgan uchta bosqichning bajarilishini tasvirlaydi.


  1. Download 296.57 Kb.

    Do'stlaringiz bilan baham:
1   2   3   4   5   6




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