Example #1
0
 public UdpService(int port)
 {
     _port     = port;
     _clients  = new ConcurrentBag <UdpClientData>();
     _endPoint = new IPEndPoint(IPAddress.Any, port);
     _socket.IOControl((int)SIO_UDP_CONNRESET, new byte[] { Convert.ToByte(false) }, null);
     _socket.Bind(_endPoint);
     _dataHandler = new UdpServiceDataHandler(_clients, _socket);
 }
Example #2
0
        public void Dispose()
        {
            _clients?.Clear();
            _clients = default;

            _socket?.Shutdown(SocketShutdown.Both);
            _socket?.Dispose();
            _socket = default;

            _endPoint = default;

            _dataHandler?.Dispose();
            _dataHandler = default;
        }