Command support improvements

This commit is contained in:
Andrea
2025-10-02 08:50:08 +02:00
parent 8bea85a5b1
commit f97f1a7bcb
6 changed files with 68 additions and 47 deletions

View File

@@ -5,6 +5,7 @@ using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SamaPager_Client
{
@@ -41,6 +42,23 @@ namespace SamaPager_Client
UdpStack.Send(msgData, msgData.Length, serverEndPoint);
}
internal string SendCommand(string command)
{
byte[] msgData = Encoding.UTF8.GetBytes(command);
UdpStack.Send(msgData, msgData.Length, serverEndPoint);
try
{
UdpStack.Client.ReceiveTimeout = 5000;
IPEndPoint receiveEndPoint = serverEndPoint;
byte[] receivedBytes = UdpStack.Receive(ref receiveEndPoint);
return $"Server replied: {Encoding.UTF8.GetString(receivedBytes)}";
}
catch(Exception ex)
{
return $"ERROR: {ex.Message}";
}
}
internal void KillClient()
{
this.UdpStack.Close();