1
0
Fork 0
mirror of https://github.com/rfc2822/GfxTablet synced 2025-10-03 09:39:16 +02:00
This commit is contained in:
wech71 2018-11-24 13:49:32 +01:00
parent 0890103556
commit cc4ad72661
2 changed files with 27 additions and 29 deletions

View file

@ -150,7 +150,7 @@ namespace GfxTabletWinDotnet
{ {
Listener.Instance.TabletEvent += Instance_TabletEvent; Listener.Instance.TabletEvent += Instance_TabletEvent;
Listener.Instance.Start(); Listener.Instance.Start();
this.txtIpAddress.Text = Listener.Instance.listenAddress.ToString(); this.txtIpAddress.Text = Listener.Instance.ListenAddress.ToString();
} }
} }
} }

View file

@ -44,44 +44,42 @@ namespace GfxTabletWinDotnet
{ {
public static readonly Listener Instance = new Listener(); public static readonly Listener Instance = new Listener();
private Listener() public IPAddress ListenAddress { get; private set; }
public string ListenHostname { get; private set; }
public IPEndPoint ListeningIpEndPoint;
private Listener()
{ {
} this.ListenHostname = Dns.GetHostName();
//public Socket socket; IPHostEntry hostInfo = Dns.GetHostEntry(ListenHostname);
public IPAddress listenAddress; // Get the DNS IP addresses associated with the host.
IPAddress[] IPaddresses = hostInfo.AddressList;
ListeningIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
public void Start() var nic = NetworkInterface.GetAllNetworkInterfaces().Where(
{ o => o.OperationalStatus == OperationalStatus.Up
IPHostEntry hostInfo = Dns.GetHostEntry(Dns.GetHostName()); && o.GetIPProperties().GatewayAddresses.Count > 0).FirstOrDefault();
// Get the DNS IP addresses associated with the host.
IPAddress[] IPaddresses = hostInfo.AddressList;
//var hostEndPoint = new IPEndPoint(IPAddress.Any, Protocol.GFXTABLET_PORT); foreach (var ip in nic.GetIPProperties().UnicastAddresses)
//socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); {
//socket.Bind(hostEndPoint); if (ip.Address.AddressFamily == AddressFamily.InterNetwork) //only use ipv4
ListeningIpEndPoint = new IPEndPoint(ip.Address, 0);
}
//socket.Listen(0); ListenAddress = ListeningIpEndPoint.Address;
////socket.Listen(2); }
//socket.BeginAccept(new AsyncCallback(NewConnection), socket);
UdpClient server = new UdpClient(Protocol.GFXTABLET_PORT); public void Start()
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0); {
UdpClient server = new UdpClient(Protocol.GFXTABLET_PORT);
var nic = NetworkInterface.GetAllNetworkInterfaces().Where(o => o.OperationalStatus == OperationalStatus.Up && o.GetIPProperties().GatewayAddresses.Count>0).FirstOrDefault(); var thread = new System.Threading.Thread(delegate ()
foreach(var ip in nic.GetIPProperties().UnicastAddresses)
{
if(ip.Address.AddressFamily == AddressFamily.InterNetwork) //ignore ipv4
RemoteIpEndPoint = new IPEndPoint(ip.Address, 0);
}
listenAddress = RemoteIpEndPoint.Address;
var thread = new System.Threading.Thread(delegate ()
{ {
while (true) while (true)
{ {
Byte[] receiveBytes = server.Receive(ref RemoteIpEndPoint); IPEndPoint remoteEndpoint = null;
Byte[] receiveBytes = server.Receive(ref remoteEndpoint);
Protocol.event_packet eventData = ByteArrayToStructure<Protocol.event_packet>(receiveBytes); Protocol.event_packet eventData = ByteArrayToStructure<Protocol.event_packet>(receiveBytes);
ntohs(ref eventData.x); ntohs(ref eventData.x);