Connections shit
This commit is contained in:
@@ -16,14 +16,10 @@ namespace Server
|
||||
private byte[] totalBuffer = new byte[1024];
|
||||
private int totalBufferReceived = 0;
|
||||
private SaveData saveData;
|
||||
private string username = null;
|
||||
public string username = null;
|
||||
private DateTime sessionStart;
|
||||
private string fileName;
|
||||
|
||||
|
||||
|
||||
public string Username { get; set; }
|
||||
|
||||
public Client(Communication communication, TcpClient tcpClient)
|
||||
{
|
||||
this.sessionStart = DateTime.Now;
|
||||
@@ -39,6 +35,7 @@ namespace Server
|
||||
|
||||
int receivedBytes = this.stream.EndRead(ar);
|
||||
|
||||
if (totalBufferReceived + receivedBytes > 1024)
|
||||
if (totalBufferReceived + receivedBytes > 1024)
|
||||
{
|
||||
throw new OutOfMemoryException("buffer too small");
|
||||
@@ -107,6 +104,7 @@ namespace Server
|
||||
this.username = username;
|
||||
sendMessage(DataParser.getLoginResponse("OK"));
|
||||
sendMessage(DataParser.getStartSessionJson());
|
||||
communication.NewLogin(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ClientApp\ClientApp.csproj" />
|
||||
<ProjectReference Include="..\DoctorApp\DoctorApp.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\Hashing\Hashing.projitems" Label="Shared" />
|
||||
|
||||
Reference in New Issue
Block a user