first commit

This commit is contained in:
Brady Bodily
2020-12-10 12:00:41 -07:00
commit 31a4309a47
21 changed files with 379 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
namespace Final.Simulator
{
public interface INetworkInterface
{
}
}

View File

@@ -0,0 +1,10 @@
using System;
using System.Dynamic;
namespace Final.Simulator
{
public interface INetworkInterfaceFactory
{
INetworkInterface Create(UInt16 port);
}
}

View File

@@ -0,0 +1,42 @@
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
namespace Final.Simulator
{
public class NetworkInterface : INetworkInterface
{
public UdpClient UdpClient { get; }
public Action<string> MessageRecieved;
private UInt16 _remotePort { get; }
private IPAddress _remoteIP { get; }
private UInt16 _localPort { get; }
private IPAddress _localIP { get; }
public NetworkInterface(IPAddress localIp, UInt16 localPort, )
{
_remoteEp = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
UdpClient = new UdpClient();
Task.Run(() => RegisterForMessages());
}
private void RegisterForMessages()
{
while (true)
{
var remoteEP = new IPEndPoint(_remoteIP, _remotePort);
MessageRecieved.Invoke(UdpClient.Receive(ref remoteEP).ToString());
UdpClient.Send(new byte[] {1}, 1, remoteEP);
}
}
private void TMP(object o)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,7 @@
namespace Final.Simulator
{
public class NetworkInterfaceFactory : INetworkInterfaceFactory
{
public INetworkInterface Create(ushort port) => new NetworkInterface(port);
}
}

View File

@@ -0,0 +1,18 @@
using ConsoleApp;
using DryIoc;
namespace Final.Simulator
{
public class SimulatorModule : IModule
{
public void Register(IContainer container)
{
}
public void Resolve(IContainer container)
{
}
}
}