Merge branch 'ConnectionController' of https://sourcecode.socialcoding.bosch.com/scm/~hpl2fe/polychat into ConnectionController

This commit is contained in:
Patrick Hellebrand
2021-09-22 16:21:53 +02:00
3 changed files with 45 additions and 13 deletions

View File

@@ -39,7 +39,7 @@ namespace PolyChat
public void Connect(string ip)
{
Debug.WriteLine("--- Controller.Connect ---");
Connections.Add(ip, new Connection(ip, PORT, Data => OnMessage(ip, Data)));
Connections.Add(ip, new Connection(ip, PORT, Data => OnMessage(ip, Data), CloseChat));
}
private void Serve()
@@ -61,7 +61,7 @@ namespace PolyChat
Debug.WriteLine("--- initial packet received ---");
string ForeignIp = data[0].ToString();
//Todo deserialize inital packet and extract ip address
Connections.Add(ForeignIp, new Connection(socket, Data => OnMessage(ForeignIp, Data)));
Connections.Add(ForeignIp, new Connection(socket, Data => OnMessage(ForeignIp, Data), CloseChat));
UIController.OnIncomingConnection(ForeignIp);
});
});
@@ -91,6 +91,15 @@ namespace PolyChat
else Debug.WriteLine("Undefined: " + data);
}
public void CloseChat(string IP, bool wasConnected = true)
{
Connections[IP].Close();
Connections.Remove(IP);
UIController.OnChatPartnerDeleted(IP);
if(!wasConnected)
UIController.ShowConnectionError(IP, $"Connection to {IP} failed...");
}
public string getIP()
{
IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());