• Mavzu: Multicast soket asosidagi dasturni yaratish Ishning maqsadi
  • 4-topshiriq 4-amaliy ish.
  • Muhammad al-xorazmiy nomidagitoshkent axborot texnologiyalariuniversitetifarg’onafiliali kompyuterinjiniringifakulteti716–20 guruhtalabasi karimov Anvarjoning Tanlov fani (




    Download 299,88 Kb.
    Sana20.02.2024
    Hajmi299,88 Kb.
    #159295
    Bog'liq
    2-dedline Tarmoqni dasturlash
    Ботирхонов Бехзод Бахтиёр уғли Ru, Intelektual tahlil 1.2.3, 1-dedline Tarmoqni dasturlash, 1-laboratoriya ishi mavzu Tarmoq simulyatorlari bilan ishlash. -ADministratsiyalash, GENOMLARDAGI OQSIL STRUKTURASINI ANIQLASH 3, Jismoniy tarbiya va sportni boshqarish, HARAKAT M T, SAYFULLO, 1578738782



    O’ZBEKISTONRESPUBLIKASIRAQAMLITEXNOLOGIYALARVAZIRLIGI


    MUHAMMAD AL-XORAZMIY NOMIDAGITOSHKENT AXBOROT TEXNOLOGIYALARIUNIVERSITETIFARG’ONAFILIALI


    KOMPYUTERINJINIRINGIFAKULTETI716–20 GURUHTALABASI

    Karimov Anvarjoning
    Tanlov fani ((Tarmoqni dasturlash)


    Amaliymashg’ulot

    FARG’ONA–2024 yil


    3-amaliy ish.

    Multicast soketasosidagidasturniamaliyo’rganish. Fayllarniko’chirishnidasturlashniamaliyo’rganish.




    Topshirish.



    1. Multicast soketasosidagidasturhaqidama’lumotlarto’plash.

    2. Fayllarniko’chirishhaqidama’lumotlarto’plash.



    Mavzu: Multicast soket asosidagi dasturni yaratish
    Ishning maqsadi:
    Talabalarda Java dasturlash tili java.net.* va java.io.* paketlari klasslaridan foydalanib TCP kliyent-server tarmoq dasturini yaratish bo‘yicha amaliy ko‘nikmalar hosil qilish.
    Nazariy qism:
    UDP protokoli asosida multicast dasturini yaratish. Java UDP datagramma va TCP soketlaridan foydalangan holda tarmoq ilovalarini ishlab chiqish imkonini beradi. UDP soketlari ilovalarning tarmoq orqali o‘zaro ishlashi uchun UDP protokolidan foydalanadi. UDP ulanish o‘rnatish zaruriyatisiz tez va ishonchsiz protokoldir. java.net paketi Java ilovasida UDP soketidan foydalanish imkonini beruvchi quyidagi ikki klassni o‘z ichiga oladi: 
    - DatagramPacket klassi; 
    - DatagramSocket klassi.
    DatagramPacket va DatagramSocket klasslari. DatagramPacket obyekti tarmoq orqali uzatiladigan yoki qabul qilinadigan datagramma paketlaridan iborat bo‘lgan ma’lumotlar konteyneridir. Quyidagi konstruktorlar DatagramPacket obyektlarini initsializatsiya qilish uchun ishlatiladi:
    - public DatagramPacket(byte[] buffer, int buffer_length): ma’lumotlarni byte massivida qabul qiladigan va saqlaydigan DatagramPacket obyektini yaratadi. Byte massivining bufer uzunligi buffer_length ikkinchi parametri tomonidan beriladi. 
    - public DatagramPacket(byte[] buffer, int buffer_length, InetAddress address, int port): berilgan uzunlikdagi ma’lumotlar paketlarini uzatuvchi DatagramPacket obyektini yaratadi. Ma’lumotlar paketlari kompyuterga IP-adres va parametr sifatida beriladigan port nomeri bilan uzatiladi.


    1.Serverni ishlatishkodlari:
    #server.py

    import socket


    import struct

    multicast_group = '224.3.29.71'


    server_address = ('', 5001)

    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)


    sock.bind(server_address)

    def odd_char(text: str) ->str:


    word = str(float(text)**3)
    return word

    # Tell the operating system to add the socket to the multicast group


    # on all interfaces.
    group = socket.inet_aton(multicast_group)
    mreq = struct.pack('4sL', group, socket.INADDR_ANY)
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)

    while True:


    data, address = sock.recvfrom(1024)

    print(f'received {len(data)} bytes from {address}')


    print(data)

    print('sending acknowledgement to', address)


    sock.sendto(f'{odd_char(data.decode())}'.encode(), address)

    2.Clientni ishlatish kodlari:


    #client.py

    import socket


    import struct

    multicast_group = ('224.3.29.71', 5001)


    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)

    # Set the time-to-live for messages to 1 so they do not go past the
    # local network segment.
    ttl = struct.pack('b', 1)
    sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, ttl)

    try:


    # Send data to the multicast group
    # print(f'sending {message}')
    # sent = sock.sendto(message.encode(), multicast_group)

    while True:


    a = input("Serverga xabar jo'nating: ").encode()
    try:
    sock.sendto(a, multicast_group)
    data, server = sock.recvfrom(16)
    except socket.timeout:
    print('timed out, no more responses')
    break
    else:
    print(f' Serverdan kelgan xabar: {data.decode()} ')

    finally:
    print('closing socket')


    sock.close()


    4-topshiriq
    4-amaliy ish.
    Tarmoqdako’poqimlilikvamultipleksing (Multithreading va Multiplexing). Tarmoqdafayllarniboshqarish (File Handling).


    Topshirish.



    1. Multithreading va Multiplexinghaqidama’lumotto’plash

    2. File Handlinghaqidama’lumotto’plash

    Download 299,88 Kb.




    Download 299,88 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Muhammad al-xorazmiy nomidagitoshkent axborot texnologiyalariuniversitetifarg’onafiliali kompyuterinjiniringifakulteti716–20 guruhtalabasi karimov Anvarjoning Tanlov fani (

    Download 299,88 Kb.