From 2e9a712e71ae38086070d95a78c561bdc4b3a467 Mon Sep 17 00:00:00 2001 From: PALMER Date: Fri, 3 Dec 2021 15:42:14 +1000 Subject: [PATCH] Initial Server & Client Commit Started on Interfaces - Created IManager - Created IPacket Started on Managers - Created Packet Manager Started on async client/server implementation --- Client.cs | 47 +++++++++++++++++++++++++++++++++++++++ Interfaces/IManager.cs | 13 +++++++++++ Interfaces/IPacket.cs | 13 +++++++++++ Managers/PacketManager.cs | 20 +++++++++++++++++ Server.cs | 46 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 139 insertions(+) create mode 100644 Client.cs create mode 100644 Interfaces/IManager.cs create mode 100644 Interfaces/IPacket.cs create mode 100644 Managers/PacketManager.cs create mode 100644 Server.cs diff --git a/Client.cs b/Client.cs new file mode 100644 index 0000000..9c0f576 --- /dev/null +++ b/Client.cs @@ -0,0 +1,47 @@ +using Articulate_Network.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Threading.Tasks; + +namespace Articulate_Network +{ + public class Client + { + List managers = new List(); + + TcpClient tcp; + + public Client() + { + tcp = new TcpClient(); + } + + public async Task Connect(string ip, int port) + { + return await Task.Run(() => + { + try + { + tcp.Connect(ip, port); + + return tcp; + } + catch (Exception e) + { + Console.WriteLine(e.Message); + return tcp; + } + } + ); + } + + public async Task SendPacket(IPacket packet) + { + return false; + } + } +} diff --git a/Interfaces/IManager.cs b/Interfaces/IManager.cs new file mode 100644 index 0000000..eaadacd --- /dev/null +++ b/Interfaces/IManager.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Articulate_Network.Interfaces +{ + interface IManager + { + void Initialize(); + } +} diff --git a/Interfaces/IPacket.cs b/Interfaces/IPacket.cs new file mode 100644 index 0000000..9931a22 --- /dev/null +++ b/Interfaces/IPacket.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Articulate_Network.Interfaces +{ + public interface IPacket + { + + } +} diff --git a/Managers/PacketManager.cs b/Managers/PacketManager.cs new file mode 100644 index 0000000..1bae597 --- /dev/null +++ b/Managers/PacketManager.cs @@ -0,0 +1,20 @@ +using Articulate_Network.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Articulate_Network.Managers +{ + public class PacketManager : IManager + { + List packets = new List(); + + public void Initialize() + { + Console.WriteLine(Assembly.GetEntryAssembly()); + } + } +} diff --git a/Server.cs b/Server.cs new file mode 100644 index 0000000..3fc8c33 --- /dev/null +++ b/Server.cs @@ -0,0 +1,46 @@ +using Articulate_Network.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Threading.Tasks; + +namespace Articulate_Network +{ + public class Server + { + List managers = new List(); + + TcpListener tcp; + + public async Task Start(string ip, int port) + { + tcp = new TcpListener(IPAddress.Parse(ip), port); + + bool connected = await Task.Run(() => + { + try + { + tcp.Start(); + + return true; + } + catch (Exception e) + { + Console.WriteLine(e.Message); + return false; + } + } + ); + + return false; + } + + public async Task SendPacket(IPacket packet) + { + return false; + } + } +}