Command support improvements
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user