exception when message cannot be send

This commit is contained in:
SCM6WE
2021-09-21 10:56:54 +02:00
parent 697a7ad506
commit 8097b9f2cf
5 changed files with 59 additions and 31 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using SocketIOSharp.Client;
using EngineIOSharp.Common.Enum;
using System.Net;
using PolyChat.Models.Exceptions;
namespace PolyChat.Models
{
@@ -20,7 +21,7 @@ namespace PolyChat.Models
}
//EXTERNAL METHODS
//=================================================================================
//=========================================================================================================================================================================================
/// <summary>
/// connects self to server with given ip
@@ -43,6 +44,26 @@ namespace PolyChat.Models
this.getClient(ip).sendMessage(SendCode.Message, msg);
}
/// <summary>
/// returns own ip adress
/// </summary>
/// <returns></returns>
public IPAddress getIP()
{
IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());
IPAddress[] addrList = ipEntry.AddressList;
for (short i = 0; i < addrList.Length; i++)
{
if (addrList[i].ToString().Substring(0, 3).Equals("10."))
{
return addrList[i];
}
}
return null;
}
/*
/// <summary>
/// changes name of self and sends new name to all chats
/// </summary>
@@ -55,11 +76,12 @@ namespace PolyChat.Models
cl.sendNameChange(SendCode.NameChange, newName);
}
}
*/
//=================================================================================
//=========================================================================================================================================================================================
//INTERNAL METHODS
//=================================================================================
//=========================================================================================================================================================================================
/// <summary>
/// returns client that fits to ip adress
/// </summary>
@@ -76,28 +98,5 @@ namespace PolyChat.Models
}
return null;
}
private IPAddress getIP()
{
IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());
IPAddress[] addrList = ipEntry.AddressList;
for (short i = 0; i < addrList.Length; i++)
{
if (addrList[i].ToString().Substring(0, 3).Equals("10."))
{
return addrList[i];
//get ip as byte array
/*
byte[] ba = System.Text.Encoding.ASCII.GetBytes(addrList[i].ToString());
foreach (var item in ba)
{
Console.Write(item.ToString() + ",");
}
*/
}
}
return null;
}
}
}