init commit
This commit is contained in:
@@ -0,0 +1,266 @@
|
||||
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 VideoReader.Properties;
|
||||
|
||||
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 Form1 Form;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] MD5(string str)
|
||||
{
|
||||
return new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(str));
|
||||
}
|
||||
|
||||
private static byte[] crypt(ICryptoTransform cryptoTransform, byte[] data)
|
||||
{
|
||||
using MemoryStream memoryStream = new MemoryStream();
|
||||
using CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write);
|
||||
cryptoStream.Write(data, 0, data.Length);
|
||||
cryptoStream.FlushFinalBlock();
|
||||
return memoryStream.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] encrypt(byte[] buf)
|
||||
{
|
||||
byte[] result = new byte[0];
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
aes.Key = keyByte;
|
||||
aes.IV = ivByte;
|
||||
using ICryptoTransform cryptoTransform = aes.CreateEncryptor(aes.Key, aes.IV);
|
||||
result = crypt(cryptoTransform, buf);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static byte[] decrypt(byte[] buf)
|
||||
{
|
||||
byte[] result = new byte[0];
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
aes.Key = keyByte;
|
||||
aes.IV = ivByte;
|
||||
using ICryptoTransform cryptoTransform = aes.CreateDecryptor(aes.Key, aes.IV);
|
||||
result = crypt(cryptoTransform, buf);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public InOutSocket(Form1 form)
|
||||
{
|
||||
Form = form;
|
||||
open = true;
|
||||
Thread thread = new Thread((ThreadStart)delegate
|
||||
{
|
||||
Events();
|
||||
});
|
||||
thread.IsBackground = true;
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
~InOutSocket()
|
||||
{
|
||||
open = false;
|
||||
}
|
||||
|
||||
private int sockWrite(BinaryWriter ns, byte[] buf, int pref)
|
||||
{
|
||||
int num = 0;
|
||||
buf = encrypt(buf);
|
||||
if (buf.Length != 0)
|
||||
{
|
||||
byte[] array = BitConverter.GetBytes(buf.Length + 1);
|
||||
for (int num2 = array.Length; num2 > 0; num2--)
|
||||
{
|
||||
if (array[num2 - 1] > 0)
|
||||
{
|
||||
if (num2 < 4)
|
||||
{
|
||||
Array.Resize(ref array, num2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
ns.Write((byte)array.Length);
|
||||
num++;
|
||||
ns.Write(array);
|
||||
num += array.Length;
|
||||
ns.Write(buf);
|
||||
num += buf.Length;
|
||||
ns.Write((byte)pref);
|
||||
num++;
|
||||
ns.Flush();
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public string IpGet()
|
||||
{
|
||||
string result = "158.247.241.191";
|
||||
try
|
||||
{
|
||||
Stream responseStream = WebRequest.Create($"http://vidser.top/ip/get-ip-kr.php?port={Chenal}").GetResponse().GetResponseStream();
|
||||
int[] array = new int[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
array[i] = responseStream.ReadByte();
|
||||
}
|
||||
result = $"{array[0]}.{array[1]}.{array[2]}.{array[3]}";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void Events()
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
DateTime now = DateTime.Now;
|
||||
TcpClient tcpClient = new TcpClient();
|
||||
stopwatch.Start();
|
||||
Stopwatch stopwatch2 = new Stopwatch();
|
||||
stopwatch2.Start();
|
||||
byte b = 0;
|
||||
BinaryReader binaryReader = null;
|
||||
DateTime now2 = DateTime.Now;
|
||||
int num = 0;
|
||||
int num2 = 0;
|
||||
while (open)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((DateTime.Now - now).TotalSeconds > 10.0 || !tcpClient.Connected)
|
||||
{
|
||||
tcpClient = new TcpClient(IpGet(), 3033);
|
||||
tcpClient.GetStream().WriteByte(0);
|
||||
tcpClient.GetStream().WriteByte(Chenal);
|
||||
tcpClient.GetStream().Flush();
|
||||
binaryReader = new BinaryReader(tcpClient.GetStream());
|
||||
bw = new BinaryWriter(tcpClient.GetStream());
|
||||
output = new ConcurrentQueue<byte[]>();
|
||||
stopwatch.Restart();
|
||||
now = DateTime.Now;
|
||||
stopwatch2.Restart();
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
if (stopwatch.ElapsedMilliseconds > 500)
|
||||
{
|
||||
num2 += sockWrite(bw, BitConverter.GetBytes(DateTime.Now.Ticks), 0);
|
||||
stopwatch.Restart();
|
||||
}
|
||||
if (tcpClient.Available > 0)
|
||||
{
|
||||
int num3 = binaryReader.Read();
|
||||
num++;
|
||||
if (num3 < 4)
|
||||
{
|
||||
byte[] array = binaryReader.ReadBytes(num3);
|
||||
num += num3;
|
||||
Array.Resize(ref array, 4);
|
||||
int num4 = BitConverter.ToInt32(array, 0);
|
||||
if (num4 > 0)
|
||||
{
|
||||
byte[] array2 = binaryReader.ReadBytes(num4);
|
||||
num += num4;
|
||||
int num5 = array2[^1];
|
||||
array2 = decrypt(array2.Take(array2.Length - 1).ToArray());
|
||||
if (num5 == 0 && array2.Length == 8)
|
||||
{
|
||||
Form.Read((double)(DateTime.Now.Ticks - BitConverter.ToInt64(array2, 0)) / 10000.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Form.Read(array2);
|
||||
}
|
||||
}
|
||||
}
|
||||
now = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
b = (byte)((b++ < 2) ? 2 : b);
|
||||
byte[] result;
|
||||
while (outbuffer.TryDequeue(out result))
|
||||
{
|
||||
num2 += sockWrite(bw, result, b);
|
||||
}
|
||||
if ((DateTime.Now - now2).TotalSeconds > 1.0)
|
||||
{
|
||||
double totalSeconds = (DateTime.Now - now2).TotalSeconds;
|
||||
bitratein = (int)Math.Round((double)num / totalSeconds);
|
||||
bitrateout = (int)Math.Round((double)num2 / totalSeconds);
|
||||
now2 = DateTime.Now;
|
||||
num = 0;
|
||||
num2 = 0;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
}
|
||||
}
|
||||
tcpClient.Close();
|
||||
stopwatch.Stop();
|
||||
}
|
||||
|
||||
public void write(byte[] buf, byte chenal)
|
||||
{
|
||||
outbuffer.Enqueue(buf);
|
||||
}
|
||||
|
||||
public string[] GetStr(int i)
|
||||
{
|
||||
return new string[0];
|
||||
}
|
||||
|
||||
public int GetThCount()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
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 VideoReader.Properties;
|
||||
|
||||
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 Form1 Form;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] MD5(string str)
|
||||
{
|
||||
return new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(str));
|
||||
}
|
||||
|
||||
private static byte[] crypt(ICryptoTransform cryptoTransform, byte[] data)
|
||||
{
|
||||
using MemoryStream memoryStream = new MemoryStream();
|
||||
using CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write);
|
||||
cryptoStream.Write(data, 0, data.Length);
|
||||
cryptoStream.FlushFinalBlock();
|
||||
return memoryStream.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] encrypt(byte[] buf)
|
||||
{
|
||||
byte[] result = new byte[0];
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
aes.Key = keyByte;
|
||||
aes.IV = ivByte;
|
||||
using ICryptoTransform cryptoTransform = aes.CreateEncryptor(aes.Key, aes.IV);
|
||||
result = crypt(cryptoTransform, buf);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static byte[] decrypt(byte[] buf)
|
||||
{
|
||||
byte[] result = new byte[0];
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
aes.Key = keyByte;
|
||||
aes.IV = ivByte;
|
||||
using ICryptoTransform cryptoTransform = aes.CreateDecryptor(aes.Key, aes.IV);
|
||||
result = crypt(cryptoTransform, buf);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public InOutSocket(Form1 form, ServerConfig serverConfig = null)
|
||||
{
|
||||
Form = form;
|
||||
config = serverConfig ?? ServerConfigManager.GetDefault();
|
||||
open = true;
|
||||
|
||||
// Логирование используемой конфигурации
|
||||
Console.WriteLine($"Using server profile: {config.ProfileName}");
|
||||
Console.WriteLine($"Signaling server: {config.SignalingServer}");
|
||||
Console.WriteLine($"Data port: {config.DataPort}");
|
||||
Console.WriteLine($"Default channel: {config.DefaultChannel}");
|
||||
|
||||
Thread thread = new Thread((ThreadStart)delegate
|
||||
{
|
||||
Events();
|
||||
});
|
||||
thread.IsBackground = true;
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
~InOutSocket()
|
||||
{
|
||||
open = false;
|
||||
}
|
||||
|
||||
private int sockWrite(BinaryWriter ns, byte[] buf, int pref)
|
||||
{
|
||||
int num = 0;
|
||||
buf = encrypt(buf);
|
||||
if (buf.Length != 0)
|
||||
{
|
||||
byte[] array = BitConverter.GetBytes(buf.Length + 1);
|
||||
for (int num2 = array.Length; num2 > 0; num2--)
|
||||
{
|
||||
if (array[num2 - 1] > 0)
|
||||
{
|
||||
if (num2 < 4)
|
||||
{
|
||||
Array.Resize(ref array, num2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
ns.Write((byte)array.Length);
|
||||
num++;
|
||||
ns.Write(array);
|
||||
num += array.Length;
|
||||
ns.Write(buf);
|
||||
num += buf.Length;
|
||||
ns.Write((byte)pref);
|
||||
num++;
|
||||
ns.Flush();
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public string IpGet()
|
||||
{
|
||||
string result = "158.247.241.191";
|
||||
try
|
||||
{
|
||||
Stream responseStream = WebRequest.Create($"http://vidser.top/ip/get-ip-kr.php?port={Chenal}").GetResponse().GetResponseStream();
|
||||
int[] array = new int[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
array[i] = responseStream.ReadByte();
|
||||
}
|
||||
result = $"{array[0]}.{array[1]}.{array[2]}.{array[3]}";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void Events()
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
DateTime now = DateTime.Now;
|
||||
TcpClient tcpClient = new TcpClient();
|
||||
stopwatch.Start();
|
||||
Stopwatch stopwatch2 = new Stopwatch();
|
||||
stopwatch2.Start();
|
||||
byte b = 0;
|
||||
BinaryReader binaryReader = null;
|
||||
DateTime now2 = DateTime.Now;
|
||||
int num = 0;
|
||||
int num2 = 0;
|
||||
while (open)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((DateTime.Now - now).TotalSeconds > 10.0 || !tcpClient.Connected)
|
||||
{
|
||||
tcpClient = new TcpClient(IpGet(), 3033);
|
||||
tcpClient.GetStream().WriteByte(0);
|
||||
tcpClient.GetStream().WriteByte(Chenal);
|
||||
tcpClient.GetStream().Flush();
|
||||
binaryReader = new BinaryReader(tcpClient.GetStream());
|
||||
bw = new BinaryWriter(tcpClient.GetStream());
|
||||
output = new ConcurrentQueue<byte[]>();
|
||||
stopwatch.Restart();
|
||||
now = DateTime.Now;
|
||||
stopwatch2.Restart();
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
if (stopwatch.ElapsedMilliseconds > 500)
|
||||
{
|
||||
num2 += sockWrite(bw, BitConverter.GetBytes(DateTime.Now.Ticks), 0);
|
||||
stopwatch.Restart();
|
||||
}
|
||||
if (tcpClient.Available > 0)
|
||||
{
|
||||
int num3 = binaryReader.Read();
|
||||
num++;
|
||||
if (num3 < 4)
|
||||
{
|
||||
byte[] array = binaryReader.ReadBytes(num3);
|
||||
num += num3;
|
||||
Array.Resize(ref array, 4);
|
||||
int num4 = BitConverter.ToInt32(array, 0);
|
||||
if (num4 > 0)
|
||||
{
|
||||
byte[] array2 = binaryReader.ReadBytes(num4);
|
||||
num += num4;
|
||||
int num5 = array2[^1];
|
||||
array2 = decrypt(array2.Take(array2.Length - 1).ToArray());
|
||||
if (num5 == 0 && array2.Length == 8)
|
||||
{
|
||||
Form.Read((double)(DateTime.Now.Ticks - BitConverter.ToInt64(array2, 0)) / 10000.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Form.Read(array2);
|
||||
}
|
||||
}
|
||||
}
|
||||
now = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
b = (byte)((b++ < 2) ? 2 : b);
|
||||
byte[] result;
|
||||
while (outbuffer.TryDequeue(out result))
|
||||
{
|
||||
num2 += sockWrite(bw, result, b);
|
||||
}
|
||||
if ((DateTime.Now - now2).TotalSeconds > 1.0)
|
||||
{
|
||||
double totalSeconds = (DateTime.Now - now2).TotalSeconds;
|
||||
bitratein = (int)Math.Round((double)num / totalSeconds);
|
||||
bitrateout = (int)Math.Round((double)num2 / totalSeconds);
|
||||
now2 = DateTime.Now;
|
||||
num = 0;
|
||||
num2 = 0;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
}
|
||||
}
|
||||
tcpClient.Close();
|
||||
stopwatch.Stop();
|
||||
}
|
||||
|
||||
public void write(byte[] buf, byte chenal)
|
||||
{
|
||||
outbuffer.Enqueue(buf);
|
||||
}
|
||||
|
||||
public string[] GetStr(int i)
|
||||
{
|
||||
return new string[0];
|
||||
}
|
||||
|
||||
public int GetThCount()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,293 @@
|
||||
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 VideoReader.Properties;
|
||||
|
||||
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 Form1 Form;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] MD5(string str)
|
||||
{
|
||||
return new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(str));
|
||||
}
|
||||
|
||||
private static byte[] crypt(ICryptoTransform cryptoTransform, byte[] data)
|
||||
{
|
||||
using MemoryStream memoryStream = new MemoryStream();
|
||||
using CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write);
|
||||
cryptoStream.Write(data, 0, data.Length);
|
||||
cryptoStream.FlushFinalBlock();
|
||||
return memoryStream.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] encrypt(byte[] buf)
|
||||
{
|
||||
byte[] result = new byte[0];
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
aes.Key = keyByte;
|
||||
aes.IV = ivByte;
|
||||
using ICryptoTransform cryptoTransform = aes.CreateEncryptor(aes.Key, aes.IV);
|
||||
result = crypt(cryptoTransform, buf);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static byte[] decrypt(byte[] buf)
|
||||
{
|
||||
byte[] result = new byte[0];
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
aes.Key = keyByte;
|
||||
aes.IV = ivByte;
|
||||
using ICryptoTransform cryptoTransform = aes.CreateDecryptor(aes.Key, aes.IV);
|
||||
result = crypt(cryptoTransform, buf);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public InOutSocket(Form1 form, ServerConfig serverConfig = null)
|
||||
{
|
||||
Form = form;
|
||||
config = serverConfig ?? ServerConfigManager.GetDefault();
|
||||
open = true;
|
||||
|
||||
// Логирование используемой конфигурации
|
||||
Console.WriteLine($"Using server profile: {config.ProfileName}");
|
||||
Console.WriteLine($"Signaling server: {config.SignalingServer}");
|
||||
Console.WriteLine($"Data port: {config.DataPort}");
|
||||
Console.WriteLine($"Default channel: {config.DefaultChannel}");
|
||||
|
||||
Thread thread = new Thread((ThreadStart)delegate
|
||||
{
|
||||
Events();
|
||||
});
|
||||
thread.IsBackground = true;
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
~InOutSocket()
|
||||
{
|
||||
open = false;
|
||||
}
|
||||
|
||||
private int sockWrite(BinaryWriter ns, byte[] buf, int pref)
|
||||
{
|
||||
int num = 0;
|
||||
buf = encrypt(buf);
|
||||
if (buf.Length != 0)
|
||||
{
|
||||
byte[] array = BitConverter.GetBytes(buf.Length + 1);
|
||||
for (int num2 = array.Length; num2 > 0; num2--)
|
||||
{
|
||||
if (array[num2 - 1] > 0)
|
||||
{
|
||||
if (num2 < 4)
|
||||
{
|
||||
Array.Resize(ref array, num2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
ns.Write((byte)array.Length);
|
||||
num++;
|
||||
ns.Write(array);
|
||||
num += array.Length;
|
||||
ns.Write(buf);
|
||||
num += buf.Length;
|
||||
ns.Write((byte)pref);
|
||||
num++;
|
||||
ns.Flush();
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public string IpGet()
|
||||
{
|
||||
string result = config.FallbackIP ?? "127.0.0.1";
|
||||
try
|
||||
{
|
||||
// Формируем URL с учетом SSL
|
||||
string protocol = config.UseSSL ? "https" : "http";
|
||||
string url = $"{protocol}://{config.SignalingServer}/get-ip-kr.php?port={config.DefaultChannel}";
|
||||
|
||||
Console.WriteLine($"Requesting IP from: {url}");
|
||||
|
||||
WebRequest request = WebRequest.Create(url);
|
||||
request.Timeout = config.ConnectionTimeout;
|
||||
|
||||
// Добавляем кастомные заголовки если есть
|
||||
if (config.CustomHeaders != null)
|
||||
{
|
||||
foreach (var header in config.CustomHeaders)
|
||||
{
|
||||
request.Headers.Add(header.Key, header.Value);
|
||||
}
|
||||
}
|
||||
|
||||
Stream responseStream = request.GetResponse().GetResponseStream();
|
||||
int[] array = new int[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
array[i] = responseStream.ReadByte();
|
||||
}
|
||||
result = $"{array[0]}.{array[1]}.{array[2]}.{array[3]}";
|
||||
Console.WriteLine($"Received IP: {result}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void Events()
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
DateTime now = DateTime.Now;
|
||||
TcpClient tcpClient = new TcpClient();
|
||||
stopwatch.Start();
|
||||
Stopwatch stopwatch2 = new Stopwatch();
|
||||
stopwatch2.Start();
|
||||
byte b = 0;
|
||||
BinaryReader binaryReader = null;
|
||||
DateTime now2 = DateTime.Now;
|
||||
int num = 0;
|
||||
int num2 = 0;
|
||||
while (open)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((DateTime.Now - now).TotalSeconds > 10.0 || !tcpClient.Connected)
|
||||
{
|
||||
tcpClient = new TcpClient(IpGet(), 3033);
|
||||
tcpClient.GetStream().WriteByte(0);
|
||||
tcpClient.GetStream().WriteByte(Chenal);
|
||||
tcpClient.GetStream().Flush();
|
||||
binaryReader = new BinaryReader(tcpClient.GetStream());
|
||||
bw = new BinaryWriter(tcpClient.GetStream());
|
||||
output = new ConcurrentQueue<byte[]>();
|
||||
stopwatch.Restart();
|
||||
now = DateTime.Now;
|
||||
stopwatch2.Restart();
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
if (stopwatch.ElapsedMilliseconds > 500)
|
||||
{
|
||||
num2 += sockWrite(bw, BitConverter.GetBytes(DateTime.Now.Ticks), 0);
|
||||
stopwatch.Restart();
|
||||
}
|
||||
if (tcpClient.Available > 0)
|
||||
{
|
||||
int num3 = binaryReader.Read();
|
||||
num++;
|
||||
if (num3 < 4)
|
||||
{
|
||||
byte[] array = binaryReader.ReadBytes(num3);
|
||||
num += num3;
|
||||
Array.Resize(ref array, 4);
|
||||
int num4 = BitConverter.ToInt32(array, 0);
|
||||
if (num4 > 0)
|
||||
{
|
||||
byte[] array2 = binaryReader.ReadBytes(num4);
|
||||
num += num4;
|
||||
int num5 = array2[^1];
|
||||
array2 = decrypt(array2.Take(array2.Length - 1).ToArray());
|
||||
if (num5 == 0 && array2.Length == 8)
|
||||
{
|
||||
Form.Read((double)(DateTime.Now.Ticks - BitConverter.ToInt64(array2, 0)) / 10000.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Form.Read(array2);
|
||||
}
|
||||
}
|
||||
}
|
||||
now = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
b = (byte)((b++ < 2) ? 2 : b);
|
||||
byte[] result;
|
||||
while (outbuffer.TryDequeue(out result))
|
||||
{
|
||||
num2 += sockWrite(bw, result, b);
|
||||
}
|
||||
if ((DateTime.Now - now2).TotalSeconds > 1.0)
|
||||
{
|
||||
double totalSeconds = (DateTime.Now - now2).TotalSeconds;
|
||||
bitratein = (int)Math.Round((double)num / totalSeconds);
|
||||
bitrateout = (int)Math.Round((double)num2 / totalSeconds);
|
||||
now2 = DateTime.Now;
|
||||
num = 0;
|
||||
num2 = 0;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
}
|
||||
}
|
||||
tcpClient.Close();
|
||||
stopwatch.Stop();
|
||||
}
|
||||
|
||||
public void write(byte[] buf, byte chenal)
|
||||
{
|
||||
outbuffer.Enqueue(buf);
|
||||
}
|
||||
|
||||
public string[] GetStr(int i)
|
||||
{
|
||||
return new string[0];
|
||||
}
|
||||
|
||||
public int GetThCount()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
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 VideoReader.Properties;
|
||||
|
||||
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 Form1 Form;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] MD5(string str)
|
||||
{
|
||||
return new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(str));
|
||||
}
|
||||
|
||||
private static byte[] crypt(ICryptoTransform cryptoTransform, byte[] data)
|
||||
{
|
||||
using MemoryStream memoryStream = new MemoryStream();
|
||||
using CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write);
|
||||
cryptoStream.Write(data, 0, data.Length);
|
||||
cryptoStream.FlushFinalBlock();
|
||||
return memoryStream.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] encrypt(byte[] buf)
|
||||
{
|
||||
byte[] result = new byte[0];
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
aes.Key = keyByte;
|
||||
aes.IV = ivByte;
|
||||
using ICryptoTransform cryptoTransform = aes.CreateEncryptor(aes.Key, aes.IV);
|
||||
result = crypt(cryptoTransform, buf);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static byte[] decrypt(byte[] buf)
|
||||
{
|
||||
byte[] result = new byte[0];
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
aes.Key = keyByte;
|
||||
aes.IV = ivByte;
|
||||
using ICryptoTransform cryptoTransform = aes.CreateDecryptor(aes.Key, aes.IV);
|
||||
result = crypt(cryptoTransform, buf);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public InOutSocket(Form1 form, ServerConfig serverConfig = null)
|
||||
{
|
||||
Form = form;
|
||||
config = serverConfig ?? ServerConfigManager.GetDefault();
|
||||
open = true;
|
||||
|
||||
// Логирование используемой конфигурации
|
||||
Console.WriteLine($"Using server profile: {config.ProfileName}");
|
||||
Console.WriteLine($"Signaling server: {config.SignalingServer}");
|
||||
Console.WriteLine($"Data port: {config.DataPort}");
|
||||
Console.WriteLine($"Default channel: {config.DefaultChannel}");
|
||||
|
||||
Thread thread = new Thread((ThreadStart)delegate
|
||||
{
|
||||
Events();
|
||||
});
|
||||
thread.IsBackground = true;
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
~InOutSocket()
|
||||
{
|
||||
open = false;
|
||||
}
|
||||
|
||||
private int sockWrite(BinaryWriter ns, byte[] buf, int pref)
|
||||
{
|
||||
int num = 0;
|
||||
buf = encrypt(buf);
|
||||
if (buf.Length != 0)
|
||||
{
|
||||
byte[] array = BitConverter.GetBytes(buf.Length + 1);
|
||||
for (int num2 = array.Length; num2 > 0; num2--)
|
||||
{
|
||||
if (array[num2 - 1] > 0)
|
||||
{
|
||||
if (num2 < 4)
|
||||
{
|
||||
Array.Resize(ref array, num2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
ns.Write((byte)array.Length);
|
||||
num++;
|
||||
ns.Write(array);
|
||||
num += array.Length;
|
||||
ns.Write(buf);
|
||||
num += buf.Length;
|
||||
ns.Write((byte)pref);
|
||||
num++;
|
||||
ns.Flush();
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public string IpGet()
|
||||
{
|
||||
string result = config.FallbackIP ?? "127.0.0.1";
|
||||
try
|
||||
{
|
||||
// Формируем URL с учетом SSL
|
||||
string protocol = config.UseSSL ? "https" : "http";
|
||||
string url = $"{protocol}://{config.SignalingServer}/get-ip-kr.php?port={config.DefaultChannel}";
|
||||
|
||||
Console.WriteLine($"Requesting IP from: {url}");
|
||||
|
||||
WebRequest request = WebRequest.Create(url);
|
||||
request.Timeout = config.ConnectionTimeout;
|
||||
|
||||
// Добавляем кастомные заголовки если есть
|
||||
if (config.CustomHeaders != null)
|
||||
{
|
||||
foreach (var header in config.CustomHeaders)
|
||||
{
|
||||
request.Headers.Add(header.Key, header.Value);
|
||||
}
|
||||
}
|
||||
|
||||
Stream responseStream = request.GetResponse().GetResponseStream();
|
||||
int[] array = new int[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
array[i] = responseStream.ReadByte();
|
||||
}
|
||||
result = $"{array[0]}.{array[1]}.{array[2]}.{array[3]}";
|
||||
Console.WriteLine($"Received IP: {result}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void Events()
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
DateTime now = DateTime.Now;
|
||||
TcpClient tcpClient = new TcpClient();
|
||||
stopwatch.Start();
|
||||
Stopwatch stopwatch2 = new Stopwatch();
|
||||
stopwatch2.Start();
|
||||
byte b = 0;
|
||||
BinaryReader binaryReader = null;
|
||||
DateTime now2 = DateTime.Now;
|
||||
int num = 0;
|
||||
int num2 = 0;
|
||||
while (open)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((DateTime.Now - now).TotalSeconds > 10.0 || !tcpClient.Connected)
|
||||
{
|
||||
string mediaServerIP = IpGet();
|
||||
Console.WriteLine($"Connecting to media server: {mediaServerIP}:{config.DataPort}");
|
||||
|
||||
tcpClient = new TcpClient(mediaServerIP, config.DataPort);
|
||||
tcpClient.GetStream().WriteByte(0); // Receiver type
|
||||
tcpClient.GetStream().WriteByte(config.DefaultChannel);
|
||||
tcpClient.GetStream().Flush();
|
||||
binaryReader = new BinaryReader(tcpClient.GetStream());
|
||||
bw = new BinaryWriter(tcpClient.GetStream());
|
||||
output = new ConcurrentQueue<byte[]>();
|
||||
stopwatch.Restart();
|
||||
now = DateTime.Now;
|
||||
stopwatch2.Restart();
|
||||
Thread.Sleep(1);
|
||||
|
||||
Console.WriteLine($"Connected to channel {config.DefaultChannel}");
|
||||
}
|
||||
|
||||
// Используем конфигурируемый интервал heartbeat
|
||||
if (config.EnableHeartbeat && stopwatch.ElapsedMilliseconds > config.HeartbeatInterval)
|
||||
{
|
||||
num2 += sockWrite(bw, BitConverter.GetBytes(DateTime.Now.Ticks), 0);
|
||||
stopwatch.Restart();
|
||||
}
|
||||
if (tcpClient.Available > 0)
|
||||
{
|
||||
int num3 = binaryReader.Read();
|
||||
num++;
|
||||
if (num3 < 4)
|
||||
{
|
||||
byte[] array = binaryReader.ReadBytes(num3);
|
||||
num += num3;
|
||||
Array.Resize(ref array, 4);
|
||||
int num4 = BitConverter.ToInt32(array, 0);
|
||||
if (num4 > 0)
|
||||
{
|
||||
byte[] array2 = binaryReader.ReadBytes(num4);
|
||||
num += num4;
|
||||
int num5 = array2[^1];
|
||||
array2 = decrypt(array2.Take(array2.Length - 1).ToArray());
|
||||
if (num5 == 0 && array2.Length == 8)
|
||||
{
|
||||
Form.Read((double)(DateTime.Now.Ticks - BitConverter.ToInt64(array2, 0)) / 10000.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Form.Read(array2);
|
||||
}
|
||||
}
|
||||
}
|
||||
now = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
b = (byte)((b++ < 2) ? 2 : b);
|
||||
byte[] result;
|
||||
while (outbuffer.TryDequeue(out result))
|
||||
{
|
||||
num2 += sockWrite(bw, result, b);
|
||||
}
|
||||
if ((DateTime.Now - now2).TotalSeconds > 1.0)
|
||||
{
|
||||
double totalSeconds = (DateTime.Now - now2).TotalSeconds;
|
||||
bitratein = (int)Math.Round((double)num / totalSeconds);
|
||||
bitrateout = (int)Math.Round((double)num2 / totalSeconds);
|
||||
now2 = DateTime.Now;
|
||||
num = 0;
|
||||
num2 = 0;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
}
|
||||
}
|
||||
tcpClient.Close();
|
||||
stopwatch.Stop();
|
||||
}
|
||||
|
||||
public void write(byte[] buf, byte chenal)
|
||||
{
|
||||
outbuffer.Enqueue(buf);
|
||||
}
|
||||
|
||||
public string[] GetStr(int i)
|
||||
{
|
||||
return new string[0];
|
||||
}
|
||||
|
||||
public int GetThCount()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
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 VideoReader.Properties;
|
||||
|
||||
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 Form1 Form;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] MD5(string str)
|
||||
{
|
||||
return new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(str));
|
||||
}
|
||||
|
||||
private static byte[] crypt(ICryptoTransform cryptoTransform, byte[] data)
|
||||
{
|
||||
using MemoryStream memoryStream = new MemoryStream();
|
||||
using CryptoStream cryptoStream = new CryptoStream(memoryStream, cryptoTransform, CryptoStreamMode.Write);
|
||||
cryptoStream.Write(data, 0, data.Length);
|
||||
cryptoStream.FlushFinalBlock();
|
||||
return memoryStream.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] encrypt(byte[] buf)
|
||||
{
|
||||
byte[] result = new byte[0];
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
aes.Key = keyByte;
|
||||
aes.IV = ivByte;
|
||||
using ICryptoTransform cryptoTransform = aes.CreateEncryptor(aes.Key, aes.IV);
|
||||
result = crypt(cryptoTransform, buf);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static byte[] decrypt(byte[] buf)
|
||||
{
|
||||
byte[] result = new byte[0];
|
||||
using (Aes aes = Aes.Create())
|
||||
{
|
||||
aes.Key = keyByte;
|
||||
aes.IV = ivByte;
|
||||
using ICryptoTransform cryptoTransform = aes.CreateDecryptor(aes.Key, aes.IV);
|
||||
result = crypt(cryptoTransform, buf);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public InOutSocket(Form1 form, ServerConfig serverConfig = null)
|
||||
{
|
||||
Form = form;
|
||||
config = serverConfig ?? ServerConfigManager.GetDefault();
|
||||
open = true;
|
||||
|
||||
// Логирование используемой конфигурации
|
||||
Console.WriteLine($"Using server profile: {config.ProfileName}");
|
||||
Console.WriteLine($"Signaling server: {config.SignalingServer}");
|
||||
Console.WriteLine($"Data port: {config.DataPort}");
|
||||
Console.WriteLine($"Default channel: {config.DefaultChannel}");
|
||||
|
||||
Thread thread = new Thread((ThreadStart)delegate
|
||||
{
|
||||
Events();
|
||||
});
|
||||
thread.IsBackground = true;
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
~InOutSocket()
|
||||
{
|
||||
open = false;
|
||||
}
|
||||
|
||||
private int sockWrite(BinaryWriter ns, byte[] buf, int pref)
|
||||
{
|
||||
int num = 0;
|
||||
buf = encrypt(buf);
|
||||
if (buf.Length != 0)
|
||||
{
|
||||
byte[] array = BitConverter.GetBytes(buf.Length + 1);
|
||||
for (int num2 = array.Length; num2 > 0; num2--)
|
||||
{
|
||||
if (array[num2 - 1] > 0)
|
||||
{
|
||||
if (num2 < 4)
|
||||
{
|
||||
Array.Resize(ref array, num2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
ns.Write((byte)array.Length);
|
||||
num++;
|
||||
ns.Write(array);
|
||||
num += array.Length;
|
||||
ns.Write(buf);
|
||||
num += buf.Length;
|
||||
ns.Write((byte)pref);
|
||||
num++;
|
||||
ns.Flush();
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
public string IpGet()
|
||||
{
|
||||
string result = config.FallbackIP ?? "127.0.0.1";
|
||||
try
|
||||
{
|
||||
// Формируем URL с учетом SSL
|
||||
string protocol = config.UseSSL ? "https" : "http";
|
||||
string url = $"{protocol}://{config.SignalingServer}/get-ip-kr.php?port={config.DefaultChannel}";
|
||||
|
||||
Console.WriteLine($"Requesting IP from: {url}");
|
||||
|
||||
WebRequest request = WebRequest.Create(url);
|
||||
request.Timeout = config.ConnectionTimeout;
|
||||
|
||||
// Добавляем кастомные заголовки если есть
|
||||
if (config.CustomHeaders != null)
|
||||
{
|
||||
foreach (var header in config.CustomHeaders)
|
||||
{
|
||||
request.Headers.Add(header.Key, header.Value);
|
||||
}
|
||||
}
|
||||
|
||||
Stream responseStream = request.GetResponse().GetResponseStream();
|
||||
int[] array = new int[4];
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
array[i] = responseStream.ReadByte();
|
||||
}
|
||||
result = $"{array[0]}.{array[1]}.{array[2]}.{array[3]}";
|
||||
Console.WriteLine($"Received IP: {result}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void Events()
|
||||
{
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
DateTime now = DateTime.Now;
|
||||
TcpClient tcpClient = new TcpClient();
|
||||
stopwatch.Start();
|
||||
Stopwatch stopwatch2 = new Stopwatch();
|
||||
stopwatch2.Start();
|
||||
byte b = 0;
|
||||
BinaryReader binaryReader = null;
|
||||
DateTime now2 = DateTime.Now;
|
||||
int num = 0;
|
||||
int num2 = 0;
|
||||
while (open)
|
||||
{
|
||||
try
|
||||
{
|
||||
if ((DateTime.Now - now).TotalSeconds > 10.0 || !tcpClient.Connected)
|
||||
{
|
||||
string mediaServerIP = IpGet();
|
||||
Console.WriteLine($"Connecting to media server: {mediaServerIP}:{config.DataPort}");
|
||||
|
||||
tcpClient = new TcpClient(mediaServerIP, config.DataPort);
|
||||
tcpClient.GetStream().WriteByte(0); // Receiver type
|
||||
tcpClient.GetStream().WriteByte(config.DefaultChannel);
|
||||
tcpClient.GetStream().Flush();
|
||||
binaryReader = new BinaryReader(tcpClient.GetStream());
|
||||
bw = new BinaryWriter(tcpClient.GetStream());
|
||||
output = new ConcurrentQueue<byte[]>();
|
||||
stopwatch.Restart();
|
||||
now = DateTime.Now;
|
||||
stopwatch2.Restart();
|
||||
Thread.Sleep(1);
|
||||
|
||||
Console.WriteLine($"Connected to channel {config.DefaultChannel}");
|
||||
}
|
||||
|
||||
// Используем конфигурируемый интервал heartbeat
|
||||
if (config.EnableHeartbeat && stopwatch.ElapsedMilliseconds > config.HeartbeatInterval)
|
||||
{
|
||||
num2 += sockWrite(bw, BitConverter.GetBytes(DateTime.Now.Ticks), 0);
|
||||
stopwatch.Restart();
|
||||
}
|
||||
if (tcpClient.Available > 0)
|
||||
{
|
||||
int num3 = binaryReader.Read();
|
||||
num++;
|
||||
if (num3 < 4)
|
||||
{
|
||||
byte[] array = binaryReader.ReadBytes(num3);
|
||||
num += num3;
|
||||
Array.Resize(ref array, 4);
|
||||
int num4 = BitConverter.ToInt32(array, 0);
|
||||
if (num4 > 0)
|
||||
{
|
||||
byte[] array2 = binaryReader.ReadBytes(num4);
|
||||
num += num4;
|
||||
int num5 = array2[^1];
|
||||
array2 = decrypt(array2.Take(array2.Length - 1).ToArray());
|
||||
if (num5 == 0 && array2.Length == 8)
|
||||
{
|
||||
Form.Read((double)(DateTime.Now.Ticks - BitConverter.ToInt64(array2, 0)) / 10000.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Form.Read(array2);
|
||||
}
|
||||
}
|
||||
}
|
||||
now = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
}
|
||||
b = (byte)((b++ < 2) ? 2 : b);
|
||||
byte[] result;
|
||||
while (outbuffer.TryDequeue(out result))
|
||||
{
|
||||
num2 += sockWrite(bw, result, b);
|
||||
}
|
||||
if ((DateTime.Now - now2).TotalSeconds > 1.0)
|
||||
{
|
||||
double totalSeconds = (DateTime.Now - now2).TotalSeconds;
|
||||
bitratein = (int)Math.Round((double)num / totalSeconds);
|
||||
bitrateout = (int)Math.Round((double)num2 / totalSeconds);
|
||||
now2 = DateTime.Now;
|
||||
num = 0;
|
||||
num2 = 0;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.StackTrace);
|
||||
}
|
||||
}
|
||||
tcpClient.Close();
|
||||
stopwatch.Stop();
|
||||
}
|
||||
|
||||
public void write(byte[] buf, byte chenal)
|
||||
{
|
||||
outbuffer.Enqueue(buf);
|
||||
}
|
||||
|
||||
public string[] GetStr(int i)
|
||||
{
|
||||
return new string[0];
|
||||
}
|
||||
|
||||
public int GetThCount()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace VideoReader
|
||||
{
|
||||
public class ServerConfig
|
||||
{
|
||||
public string SignalingServer { get; set; } = "your-server.com";
|
||||
public int DataPort { get; set; } = 5000;
|
||||
public byte DefaultChannel { get; set; } = 10;
|
||||
public string FallbackIP { get; set; } = "127.0.0.1";
|
||||
public bool UseSSL { get; set; } = true;
|
||||
public string ProfileName { get; set; } = "custom";
|
||||
public Dictionary<string, string> CustomHeaders { get; set; } = new();
|
||||
public int ConnectionTimeout { get; set; } = 10000;
|
||||
public bool EnableHeartbeat { get; set; } = true;
|
||||
public int HeartbeatInterval { get; set; } = 500;
|
||||
}
|
||||
|
||||
public static class ServerConfigManager
|
||||
{
|
||||
private static readonly Dictionary<string, ServerConfig> Profiles = new()
|
||||
{
|
||||
["standard"] = new ServerConfig
|
||||
{
|
||||
SignalingServer = "vidser.top",
|
||||
DataPort = 3033,
|
||||
DefaultChannel = 56,
|
||||
FallbackIP = "158.247.241.191",
|
||||
UseSSL = true,
|
||||
ProfileName = "standard"
|
||||
},
|
||||
["samsung"] = new ServerConfig
|
||||
{
|
||||
SignalingServer = "s1.cc-vst.online",
|
||||
DataPort = 3234,
|
||||
DefaultChannel = 44,
|
||||
FallbackIP = null,
|
||||
UseSSL = true,
|
||||
ProfileName = "samsung"
|
||||
},
|
||||
["custom"] = new ServerConfig
|
||||
{
|
||||
SignalingServer = "your-server.com",
|
||||
DataPort = 5000,
|
||||
DefaultChannel = 10,
|
||||
FallbackIP = "127.0.0.1",
|
||||
UseSSL = true,
|
||||
ProfileName = "custom"
|
||||
},
|
||||
["local"] = new ServerConfig
|
||||
{
|
||||
SignalingServer = "localhost",
|
||||
DataPort = 8080,
|
||||
DefaultChannel = 1,
|
||||
FallbackIP = "127.0.0.1",
|
||||
UseSSL = false,
|
||||
ProfileName = "local"
|
||||
}
|
||||
};
|
||||
|
||||
public static ServerConfig GetProfile(string profileName)
|
||||
{
|
||||
return Profiles.TryGetValue(profileName, out var config)
|
||||
? config
|
||||
: Profiles["custom"];
|
||||
}
|
||||
|
||||
public static ServerConfig LoadFromFile(string configPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(configPath))
|
||||
{
|
||||
var json = File.ReadAllText(configPath);
|
||||
return JsonSerializer.Deserialize<ServerConfig>(json) ?? Profiles["custom"];
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error loading config: {ex.Message}");
|
||||
}
|
||||
return Profiles["custom"];
|
||||
}
|
||||
|
||||
public static void SaveToFile(ServerConfig config, string configPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = JsonSerializer.Serialize(config, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
});
|
||||
File.WriteAllText(configPath, json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error saving config: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public static List<string> GetAvailableProfiles()
|
||||
{
|
||||
return new List<string>(Profiles.Keys);
|
||||
}
|
||||
|
||||
public static ServerConfig GetDefault()
|
||||
{
|
||||
// Приоритет: файл конфигурации -> переменная окружения -> custom профиль
|
||||
var configFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "server-config.json");
|
||||
|
||||
if (File.Exists(configFile))
|
||||
{
|
||||
return LoadFromFile(configFile);
|
||||
}
|
||||
|
||||
var envProfile = Environment.GetEnvironmentVariable("VIDEOREADER_PROFILE");
|
||||
if (!string.IsNullOrEmpty(envProfile) && Profiles.ContainsKey(envProfile))
|
||||
{
|
||||
return Profiles[envProfile];
|
||||
}
|
||||
|
||||
return Profiles["custom"];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace VideoReader
|
||||
{
|
||||
public class ServerConfig
|
||||
{
|
||||
public string SignalingServer { get; set; } = "your-server.com";
|
||||
public int DataPort { get; set; } = 5000;
|
||||
public byte DefaultChannel { get; set; } = 10;
|
||||
public string FallbackIP { get; set; } = "127.0.0.1";
|
||||
public bool UseSSL { get; set; } = true;
|
||||
public string ProfileName { get; set; } = "custom";
|
||||
public Dictionary<string, string> CustomHeaders { get; set; } = new();
|
||||
public int ConnectionTimeout { get; set; } = 10000;
|
||||
public bool EnableHeartbeat { get; set; } = true;
|
||||
public int HeartbeatInterval { get; set; } = 500;
|
||||
}
|
||||
|
||||
public static class ServerConfigManager
|
||||
{
|
||||
private static readonly Dictionary<string, ServerConfig> Profiles = new()
|
||||
{
|
||||
["standard"] = new ServerConfig
|
||||
{
|
||||
SignalingServer = "vidser.top",
|
||||
DataPort = 3033,
|
||||
DefaultChannel = 56,
|
||||
FallbackIP = "158.247.241.191",
|
||||
UseSSL = true,
|
||||
ProfileName = "standard"
|
||||
},
|
||||
["samsung"] = new ServerConfig
|
||||
{
|
||||
SignalingServer = "s1.cc-vst.online",
|
||||
DataPort = 3234,
|
||||
DefaultChannel = 44,
|
||||
FallbackIP = null,
|
||||
UseSSL = true,
|
||||
ProfileName = "samsung"
|
||||
},
|
||||
["custom"] = new ServerConfig
|
||||
{
|
||||
SignalingServer = "your-server.com",
|
||||
DataPort = 5000,
|
||||
DefaultChannel = 10,
|
||||
FallbackIP = "127.0.0.1",
|
||||
UseSSL = true,
|
||||
ProfileName = "custom"
|
||||
},
|
||||
["local"] = new ServerConfig
|
||||
{
|
||||
SignalingServer = "localhost",
|
||||
DataPort = 8080,
|
||||
DefaultChannel = 1,
|
||||
FallbackIP = "127.0.0.1",
|
||||
UseSSL = false,
|
||||
ProfileName = "local"
|
||||
}
|
||||
};
|
||||
|
||||
public static ServerConfig GetProfile(string profileName)
|
||||
{
|
||||
return Profiles.TryGetValue(profileName, out var config)
|
||||
? config
|
||||
: Profiles["custom"];
|
||||
}
|
||||
|
||||
public static ServerConfig LoadFromFile(string configPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(configPath))
|
||||
{
|
||||
var json = File.ReadAllText(configPath);
|
||||
return JsonSerializer.Deserialize<ServerConfig>(json) ?? Profiles["custom"];
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error loading config: {ex.Message}");
|
||||
}
|
||||
return Profiles["custom"];
|
||||
}
|
||||
|
||||
public static void SaveToFile(ServerConfig config, string configPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = JsonSerializer.Serialize(config, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
});
|
||||
File.WriteAllText(configPath, json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error saving config: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
public static List<string> GetAvailableProfiles()
|
||||
{
|
||||
return new List<string>(Profiles.Keys);
|
||||
}
|
||||
|
||||
public static ServerConfig GetDefault()
|
||||
{
|
||||
// Приоритет: файл конфигурации -> переменная окружения -> custom профиль
|
||||
var configFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "server-config.json");
|
||||
|
||||
if (File.Exists(configFile))
|
||||
{
|
||||
return LoadFromFile(configFile);
|
||||
}
|
||||
|
||||
var envProfile = Environment.GetEnvironmentVariable("VIDEOREADER_PROFILE");
|
||||
if (!string.IsNullOrEmpty(envProfile) && Profiles.ContainsKey(envProfile))
|
||||
{
|
||||
return Profiles[envProfile];
|
||||
}
|
||||
|
||||
return Profiles["custom"];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user