79 lines
2.4 KiB
C#
79 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
using SafeNetLib;
|
|
|
|
|
|
namespace MotoTRBO_SOC
|
|
{
|
|
class TallysmanSendThread
|
|
{
|
|
//public static IPEndPoint iep;
|
|
//public static Socket server;
|
|
private ushort Port = 0;
|
|
//private string radioIP;
|
|
//private UdpMulticast udpMulticastBusConnection = null;
|
|
UdpClient udpClient;
|
|
private String mIP;
|
|
private Int32 mPort;
|
|
|
|
public TallysmanSendThread(ushort port, String multicastID, String multicastPort)
|
|
{
|
|
Port = port;
|
|
mIP = multicastID;
|
|
mPort = Int32.Parse(multicastPort);
|
|
}
|
|
|
|
public void handleConnection()
|
|
{
|
|
/*
|
|
try
|
|
{
|
|
udpMulticastBusConnection = new UdpMulticast(mIP, mPort);
|
|
udpMulticastBusConnection.OnNewDataRecv += new UdpMulticast.newData4Send(udp_OnNewDataReceived);
|
|
udpMulticastBusConnection.StartListen();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Utils.WriteLine("TallysmanSendThread exception while joining the multicast group: " + ex.ToString(), ConsoleColor.Red);
|
|
}
|
|
*/
|
|
try
|
|
{
|
|
udpClient = new UdpClient();
|
|
udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
|
udpClient.Client.Bind(new IPEndPoint(IPAddress.Any, Port));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Utils.WriteLine("TallysmanSendThread handleConnection exception while creating udpClient: " + ex.ToString(), ConsoleColor.Red);
|
|
}
|
|
|
|
while (MotoTRBO_GW.running) { Thread.Sleep(100); }
|
|
}
|
|
|
|
void udp_OnNewDataReceived(byte[] data, int dataLen)
|
|
{
|
|
try
|
|
{
|
|
Utils.WriteLine("TallysmanSendThread udp_OnNewDataReceived", ConsoleColor.Gray);
|
|
string str = System.Text.Encoding.ASCII.GetString(data, 0, dataLen);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Utils.WriteLine("udp_OnNewDataReceived " + ex.ToString(), ConsoleColor.Red);
|
|
}
|
|
}
|
|
|
|
public void sendTallysmanCommand(String ID, String _gpio, String _type, int transactionID)
|
|
{
|
|
}
|
|
|
|
|
|
}
|
|
}
|