Files
SuperVPN/.history/desktop_global/InOutSocketSimple_20251009102951.cs
2025-10-12 10:59:34 +09:00

81 lines
2.4 KiB
C#

using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace VideoReader
{
internal class InOutSocket
{
public int bitrateout = 0;
public int bitratein = 0;
private static byte[] keyByte = MD5("73!2#qweaSdzxc4r");
private static byte[] ivByte = MD5("0_=op[l:',./vf73");
private bool open;
private ServerConfig config;
private ConcurrentQueue<byte[]> outbuffer = new ConcurrentQueue<byte[]>();
private BinaryWriter bw;
private ConcurrentQueue<byte[]> output = new ConcurrentQueue<byte[]>();
private bool noblock = true;
// Новые поля для детального логгирования
private TcpClient tcpClient;
private NetworkStream networkStream;
private Thread receiveThread;
private Thread sendThread;
private bool isRunning = false;
private long packetCounter = 0;
private DateTime connectionStartTime;
public bool opened
{
get { return open; }
set { open = value; }
}
public InOutSocket()
{
config = ServerConfig.LoadConfig();
Console.WriteLine($"InOutSocket initialized with server: {config.ServerAddress}:{config.Port}");
}
private static byte[] MD5(string input)
{
using (var md5 = System.Security.Cryptography.MD5.Create())
{
return md5.ComputeHash(Encoding.UTF8.GetBytes(input));
}
}
public void Connect()
{
try
{
Console.WriteLine($"Attempting to connect to {config.ServerAddress}:{config.Port}...");
// Здесь был бы код подключения к серверу
opened = true;
Console.WriteLine("Connection established successfully");
}
catch (Exception ex)
{
Console.WriteLine($"Connection failed: {ex.Message}");
opened = false;
}
}
public void Disconnect()
{
opened = false;
Console.WriteLine("Disconnected from server");
}
}
}