|
Masalani yechishning algoritmi va dasturi
|
bet | 7/22 | Sana | 11.09.2024 | Hajmi | 46,67 Kb. | | #270884 |
Bog'liq Multimedia3.2 Masalani yechishning algoritmi va dasturi:
Tarmoq orqali multimedia fayllarni uzatish uchun server va mijoz tizimini tashkil etish.
Fayllarni uzatish va qabul qilish jarayonini sinxronizatsiya qilish.
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.
|
| |