Connections shit

This commit is contained in:
fabjuuuh
2020-10-14 13:05:56 +02:00
parent 301f6b447f
commit 25176dbaeb
13 changed files with 186 additions and 34 deletions

View File

@@ -4,7 +4,7 @@ using System.IO.Pipes;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using ClientApp.Utils;
using DoctorApp.Utils;
namespace Server
{
@@ -13,7 +13,6 @@ namespace Server
private TcpListener listener;
private List<Client> clients;
private Client doctor;
public Communication(TcpListener listener)
{
this.listener = listener;
@@ -35,15 +34,15 @@ namespace Server
var tcpClient = listener.EndAcceptTcpClient(ar);
Console.WriteLine($"Client connected from {tcpClient.Client.RemoteEndPoint}");
clients.Add(new Client(this, tcpClient));
if (doctor == null)
/*if (doctor == null)
{
doctor = clients.ElementAt(0);
}
else
{
doctor.sendMessage(DataParser.getLoginResponse("new client"));
}
doctor.sendMessage(DataParser.getNewConnectionJson("jan"));
}*/
listener.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null);
}
@@ -51,5 +50,18 @@ namespace Server
{
clients.Remove(client);
}
public void NewLogin(Client client)
{
if (doctor == null)
{
doctor = client;
}
else
{
doctor.sendMessage(DataParser.getNewConnectionJson(client.username));
}
}
}
}