• Dastur kodi (C)
  • Dastur kodining tahlili
  • Masalani yechishning algoritmi va dasturi




    Download 46,67 Kb.
    bet7/22
    Sana11.09.2024
    Hajmi46,67 Kb.
    #270884
    1   2   3   4   5   6   7   8   9   10   ...   22
    Bog'liq
    Multimedia

    3.2 Masalani yechishning algoritmi va dasturi:

    1. Tarmoq orqali multimedia fayllarni uzatish uchun server va mijoz tizimini tashkil etish.

    2. Fayllarni uzatish va qabul qilish jarayonini sinxronizatsiya qilish.

    3. Ovoz va video fayllarni kompresslash va dekompresslash algoritmlarini qo‘llash.

    Dastur kodi (C#):
    csharp
    Копировать код
    using System;
    using System.Net;
    using System.Net.Sockets;
    using System.IO;

    public class MultimediaTransfer


    {
    public static void SendFile(string fileName, string serverIp)
    {
    TcpClient client = new TcpClient(serverIp, 8080);
    NetworkStream netStream = client.GetStream();
    FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);

    byte[] buffer = new byte[1024];


    int bytesRead;
    while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0)
    {
    netStream.Write(buffer, 0, bytesRead);
    }

    fs.Close();


    netStream.Close();
    client.Close();
    }

    public static void ReceiveFile(string saveFileName)


    {
    TcpListener listener = new TcpListener(IPAddress.Any, 8080);
    listener.Start();

    TcpClient client = listener.AcceptTcpClient();


    NetworkStream netStream = client.GetStream();
    FileStream fs = new FileStream(saveFileName, FileMode.Create, FileAccess.Write);

    byte[] buffer = new byte[1024];


    int bytesRead;
    while ((bytesRead = netStream.Read(buffer, 0, buffer.Length)) > 0)
    {
    fs.Write(buffer, 0, bytesRead);
    }

    fs.Close();


    netStream.Close();
    client.Close();
    listener.Stop();
    }
    }
    Dastur kodining tahlili:
    Yuqoridagi dasturda TcpClient va TcpListener obyektlari yordamida tarmoq orqali multimedia fayllarini uzatish va qabul qilish jarayonlari amalga oshiriladi. Fayllar dastlab serverga yuklanadi, so‘ngra mijoz tomonidan qabul qilinadi.

    Download 46,67 Kb.
    1   2   3   4   5   6   7   8   9   10   ...   22




    Download 46,67 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Masalani yechishning algoritmi va dasturi

    Download 46,67 Kb.