72 lines
2.0 KiB
C#
72 lines
2.0 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;
|
|
|
|
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");
|
|
}
|
|
}
|
|
} |