Sorgente Release 1 (Codename "Campra")
This commit is contained in:
49
SamaPager_Client/Client.cs
Normal file
49
SamaPager_Client/Client.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SamaPager_Client
|
||||
{
|
||||
internal class Client
|
||||
{
|
||||
internal int Port { get; set; }
|
||||
internal IPAddress DestinationIP { get; set; }
|
||||
internal UdpClient UdpStack { get; set; }
|
||||
private IPEndPoint serverEndPoint { get; set; }
|
||||
|
||||
internal Client(IPAddress destinationIP, int destinationPort)
|
||||
{
|
||||
this.DestinationIP = destinationIP;
|
||||
this.Port = destinationPort;
|
||||
}
|
||||
|
||||
internal string StartClient()
|
||||
{
|
||||
serverEndPoint = new IPEndPoint(this.DestinationIP, this.Port);
|
||||
try
|
||||
{
|
||||
UdpStack = new UdpClient();
|
||||
return "Serving on " + serverEndPoint;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return $"Error ({ex.Message})";
|
||||
}
|
||||
}
|
||||
|
||||
internal void SendMessage(string message)
|
||||
{
|
||||
byte[] msgData = Encoding.UTF8.GetBytes(message);
|
||||
UdpStack.Send(msgData, msgData.Length, serverEndPoint);
|
||||
}
|
||||
|
||||
internal void KillClient()
|
||||
{
|
||||
this.UdpStack.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user