first commit
This commit is contained in:
7
Simulator/Networking/INetworkInterface.cs
Normal file
7
Simulator/Networking/INetworkInterface.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Final.Simulator
|
||||
{
|
||||
public interface INetworkInterface
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
10
Simulator/Networking/INetworkInterfaceFactory.cs
Normal file
10
Simulator/Networking/INetworkInterfaceFactory.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Dynamic;
|
||||
|
||||
namespace Final.Simulator
|
||||
{
|
||||
public interface INetworkInterfaceFactory
|
||||
{
|
||||
INetworkInterface Create(UInt16 port);
|
||||
}
|
||||
}
|
||||
42
Simulator/Networking/NetworkInterface.cs
Normal file
42
Simulator/Networking/NetworkInterface.cs
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
7
Simulator/Networking/NetworkInterfaceFactory.cs
Normal file
7
Simulator/Networking/NetworkInterfaceFactory.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Final.Simulator
|
||||
{
|
||||
public class NetworkInterfaceFactory : INetworkInterfaceFactory
|
||||
{
|
||||
public INetworkInterface Create(ushort port) => new NetworkInterface(port);
|
||||
}
|
||||
}
|
||||
18
Simulator/Networking/SimulatorModule.cs
Normal file
18
Simulator/Networking/SimulatorModule.cs
Normal 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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Simulator/Program.cs
Normal file
12
Simulator/Program.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace Simulator
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
}
|
||||
}
|
||||
}
|
||||
16
Simulator/Simulator.csproj
Normal file
16
Simulator/Simulator.csproj
Normal file
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ConsoleApp\ConsoleApp.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="UdpMessages" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user