using System;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
namespace joke1
{
class Program
{
static int port = 8005;
static string address = "127.0.0.1";
static void Main(string[] args)
{
DriveInfo[] allDrivers = DriveInfo.GetDrives();
string[] dataDrive = new string[6];
foreach(DriveInfo drive in allDrivers)
{
dataDrive[0] = drive.Name + " ";
dataDrive[1] = drive.DriveType.ToString() + " ";
dataDrive[2] = drive.DriveFormat + " ";
long totalSize1 = drive.TotalSize >> 30;
long freeSpace1 = drive.AvailableFreeSpace >> 30;
dataDrive[3] = Convert.ToInt32(totalSize1).ToString() + "gb" + " ";
dataDrive[4] = Convert.ToInt32(freeSpace1).ToString() + "gb" + " ";
dataDrive[5] = drive.RootDirectory.ToString() + " ";
}
try
{
IPEndPoint ipPoint = new IPEndPoint(IPAddress.Parse(address), port);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(ipPoint);
byte[][] data = new byte[6][];
for(int i = 0; i < 6; i++)
{
data[i] = Encoding.Unicode.GetBytes(dataDrive[i]);
socket.Send(data[i]);
}
Console.WriteLine("Данные отправлены");
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadKey();
}
}
}
}
foreach(DriveInfo drive in allDrivers)
вы их перезаписываете.using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
namespace joke1
{
class Program
{
static int port = 8005;
static string address = "127.0.0.1";
static void Main(string[] args)
{
DriveInfo[] allDrivers = DriveInfo.GetDrives();
var dataDrivers = new List<string[]>();
foreach(DriveInfo drive in allDrivers)
{
string[] dataDrive = new string[6];
dataDrive[0] = drive.Name + " ";
dataDrive[1] = drive.DriveType.ToString() + " ";
dataDrive[2] = drive.DriveFormat + " ";
long totalSize1 = drive.TotalSize >> 30;
long freeSpace1 = drive.AvailableFreeSpace >> 30;
dataDrive[3] = Convert.ToInt32(totalSize1).ToString() + "gb" + " ";
dataDrive[4] = Convert.ToInt32(freeSpace1).ToString() + "gb" + " ";
dataDrive[5] = drive.RootDirectory.ToString() + " ";
dataDrivers.Add(dataDrive);
}
try
{
IPEndPoint ipPoint = new IPEndPoint(IPAddress.Parse(address), port);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(ipPoint);
foreach(var driveInfo in dataDrivers)
{
byte[][] data = new byte[6][];
for(int i = 0; i < 6; i++)
{
data[i] = Encoding.Unicode.GetBytes(driveInfo[i]);
socket.Send(data[i]);
}
}
Console.WriteLine("Данные отправлены");
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadKey();
}
}
}
}