Initial Server & Client Commit
Started on Interfaces - Created IManager - Created IPacket Started on Managers - Created Packet Manager Started on async client/server implementation
This commit is contained in:
47
Client.cs
Normal file
47
Client.cs
Normal file
@ -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<IManager> managers = new List<IManager>();
|
||||
|
||||
TcpClient tcp;
|
||||
|
||||
public Client()
|
||||
{
|
||||
tcp = new TcpClient();
|
||||
}
|
||||
|
||||
public async Task<TcpClient> 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<bool> SendPacket(IPacket packet)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
13
Interfaces/IManager.cs
Normal file
13
Interfaces/IManager.cs
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
13
Interfaces/IPacket.cs
Normal file
13
Interfaces/IPacket.cs
Normal file
@ -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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
20
Managers/PacketManager.cs
Normal file
20
Managers/PacketManager.cs
Normal file
@ -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<IPacket> packets = new List<IPacket>();
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
Console.WriteLine(Assembly.GetEntryAssembly());
|
||||
}
|
||||
}
|
||||
}
|
||||
46
Server.cs
Normal file
46
Server.cs
Normal file
@ -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<IManager> managers = new List<IManager>();
|
||||
|
||||
TcpListener tcp;
|
||||
|
||||
public async Task<bool> 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<bool> SendPacket(IPacket packet)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user