sockscape/server/Socks/MasterUdpClient.cs

51 lines
1.2 KiB
C#
Raw Normal View History

2017-06-16 21:00:01 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
2017-06-16 21:00:01 +00:00
using System.Text;
2017-08-29 20:14:44 +00:00
using System.Threading;
2017-06-16 21:00:01 +00:00
using System.Threading.Tasks;
2017-08-30 21:02:51 +00:00
using Glove;
using SockScape.Encryption;
2017-06-16 21:00:01 +00:00
2017-08-29 20:14:44 +00:00
namespace SockScape {
2017-08-30 21:02:51 +00:00
static class MasterUdpClient {
private static Key Key;
public static Cipher Encryptor { get; private set; }
private static UdpClient Sock;
2017-08-29 20:14:44 +00:00
private static Thread ListeningThread;
private static bool IsOpen;
2017-06-16 21:00:01 +00:00
public static void Initialize() {
2017-08-30 21:02:51 +00:00
if(IsOpen || ListeningThread != null)
return;
2017-08-30 21:02:51 +00:00
short port = (short)Configuration.General["Master Port"];
2017-08-29 20:14:44 +00:00
Sock = new UdpClient(Configuration.General["Master Addr"], port);
2017-08-30 21:02:51 +00:00
Key = new Key();
IsOpen = true;
2017-08-30 21:02:51 +00:00
ListeningThread = new Thread(Listener);
ListeningThread.Start();
}
2017-08-29 20:14:44 +00:00
public static void Listener() {
2017-08-30 21:02:51 +00:00
while(IsOpen) {
while(Sock.Available > 0) {
}
Thread.Sleep(1);
}
2017-08-29 20:14:44 +00:00
}
public static void Close() {
IsOpen = false;
ListeningThread.Join();
ListeningThread = null;
}
2017-06-16 21:00:01 +00:00
}
}