Exemplo n.º 1
1
        /// <summary>
        /// A connection to our server, always listening asynchronously.
        /// </summary>
        /// <param name="socket">The Socket for the connection.</param>
        /// <param name="args">The SocketAsyncEventArgs for asyncronous recieves.</param>
        /// <param name="dataReceived">A callback invoked when data is recieved.</param>
        /// <param name="disconnectedCallback">A callback invoked on disconnection.</param>
        public ServerConnection(Socket socket, SocketAsyncEventArgs args, DataReceivedCallback dataReceived,
            DisconnectedCallback disconnectedCallback)
        {
            logger = new ElibLogging("data");
            this.AuthorizationType = Securtiy.AuthorizationType.Anonymous;
            lock (this)
            {
                var remotIP = socket.RemoteEndPoint as IPEndPoint;
                var localIP = socket.LocalEndPoint as IPEndPoint;
                State state = new State()
                {
                    socket = socket,
                    dataReceived = dataReceived,
                    disconnectedCallback = disconnectedCallback,
                    Device = new Device()
                    {
                        RemoteIP = remotIP.Address.ToString(),
                        LocalIP = localIP.Address.ToString()
                    }
                };

                eventArgs = args;
                eventArgs.Completed += ReceivedCompleted;
                eventArgs.UserToken = state;

                ListenForData(eventArgs);
            }
        }
Exemplo n.º 2
0
 // Listen sockets have been created.
 public UdpSocketListener(List <Socket> listenSockets, int maxBufferPoolSize, int maxMessageSize, DataReceivedCallback dataReceivedCallback)
 {
     this.listenSockets        = listenSockets;
     this.maxMessageSize       = maxMessageSize;
     this.bufferManager        = BufferManager.CreateBufferManager(maxBufferPoolSize, maxMessageSize);
     this.dataReceivedCallback = dataReceivedCallback;
 }
Exemplo n.º 3
0
 // Listen sockets have been created.
 public UdpSocketListener(List<Socket> listenSockets, int maxBufferPoolSize, int maxMessageSize, DataReceivedCallback dataReceivedCallback)
 {
     this.listenSockets = listenSockets;
     this.maxMessageSize = maxMessageSize;
     this.bufferManager = BufferManager.CreateBufferManager(maxBufferPoolSize, maxMessageSize);
     this.dataReceivedCallback = dataReceivedCallback;
 }
Exemplo n.º 4
0
        /// <summary>
        /// A connection to our server, always listening asynchronously.
        /// </summary>
        /// <param name="socket">The Socket for the connection.</param>
        /// <param name="args">The SocketAsyncEventArgs for asyncronous recieves.</param>
        /// <param name="dataReceived">A callback invoked when data is recieved.</param>
        /// <param name="disconnectedCallback">A callback invoked on disconnection.</param>
        public ServerConnection(Socket socket, SocketAsyncEventArgs args, DataReceivedCallback dataReceived,
                                DisconnectedCallback disconnectedCallback)
        {
            logger = new ElibLogging("data");
            this.AuthorizationType = Securtiy.AuthorizationType.Anonymous;
            lock (this)
            {
                var   remotIP = socket.RemoteEndPoint as IPEndPoint;
                var   localIP = socket.LocalEndPoint as IPEndPoint;
                State state   = new State()
                {
                    socket               = socket,
                    dataReceived         = dataReceived,
                    disconnectedCallback = disconnectedCallback,
                    Device               = new Device()
                    {
                        RemoteIP = remotIP.Address.ToString(),
                        LocalIP  = localIP.Address.ToString()
                    }
                };

                eventArgs            = args;
                eventArgs.Completed += ReceivedCompleted;
                eventArgs.UserToken  = state;

                ListenForData(eventArgs);
            }
        }
 /// <summary>
 /// Fires the DataReceivedCallback.
 /// </summary>
 /// <param name="data">The data which was received.</param>
 /// <param name="remoteEndPoint">The address the data came from.</param>
 /// <param name="callback">The callback.</param>
 private void OnDataReceived(Byte[] data, IPEndPoint remoteEndPoint, DataReceivedCallback callback)
 {
     callback(this, new DataEventArgs()
     {
         RemoteEndPoint = remoteEndPoint, Data = data, Offset = 0, Length = data.Length
     });
 }
Exemplo n.º 6
0
 public UdpSocketListener(IPAddress ipAddress, int port, bool multicast, int maxBufferPoolSize, int maxMessageSize, DataReceivedCallback dataReceivedCallback)
 {
     this.ipAddress            = ipAddress;
     this.port                 = port;
     this.multicast            = multicast;
     this.maxMessageSize       = maxMessageSize;
     this.listenSockets        = null;
     this.bufferManager        = BufferManager.CreateBufferManager(maxBufferPoolSize, maxMessageSize);
     this.dataReceivedCallback = dataReceivedCallback;
 }
Exemplo n.º 7
0
 public UdpSocketListener(IPAddress ipAddress, int port, bool multicast, int maxBufferPoolSize, int maxMessageSize, DataReceivedCallback dataReceivedCallback)
 {
     this.ipAddress = ipAddress;
     this.port = port;
     this.multicast = multicast;
     this.maxMessageSize = maxMessageSize;
     this.listenSockets = null;
     this.bufferManager = BufferManager.CreateBufferManager(maxBufferPoolSize, maxMessageSize);
     this.dataReceivedCallback = dataReceivedCallback;
 }
Exemplo n.º 8
0
 public SocketServer(IPEndPoint localEndpoint,
                     DataReceivedCallback dataReceivedCallback,
                     int connectionBacklog  = 10,
                     ISerializer serializer = null,
                     Encoding encoding      = null)
     : base(localEndpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
 {
     _dataReceivedCallback = dataReceivedCallback;
     _encoding             = encoding ?? Encoding.UTF8;
     _serializer           = serializer ?? new JsonSerializer();
     _localEndpoint        = localEndpoint;
     _connectionBacklog    = connectionBacklog;
 }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            uint res = Init();

            switch (Init())
            {
            case S_OK:

                break;

            case E_ACCESSDENIED:
                MessageBox.Show("Отсутствуют права на использование: нужен USB-ключ", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);

                return;

            default:
                MessageBox.Show("Непредвиденная ошибка", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            CreateDiana(out pDiana);
            if (pDiana == IntPtr.Zero)
            {
                return;
            }

            OnDataReceived = DataReceivedCallback;
            SetDataReceivedCallback(pDiana, 0, OnDataReceived);

            OnConnectionChanged = ConnectionChangedCallback;
            SetConnectionChangedCallback(pDiana, 0, OnConnectionChanged);

            OnDianaInfo = DianaInfoCallback;
            SetDianaInfoCallback(pDiana, 0, OnDianaInfo);

            OnDispChanged = DispChangedCallback;
            SetDispChangedCallback(pDiana, 0, OnDispChanged);

            OnAmplChanged = AmplChangedCallback;
            SetAmplChangedCallback(pDiana, 0, OnAmplChanged);

            OnOptionalTypeChanged = OptionalTypeChangedCallback;
            SetOptionalTypeChangedCallback(pDiana, 0, OnOptionalTypeChanged);

            UpdateDeviceList();
        }
Exemplo n.º 10
0
        private void Start_Diana()
        {
            tiEquipment.IsEnabled = true;
            uint res = Init();

            switch (Init())
            {
            case S_OK:

                break;

            case E_ACCESSDENIED:
                System.Windows.MessageBox.Show("Отсутствуют права на использование: нужен USB-ключ", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);

                return;

            default:
                System.Windows.MessageBox.Show("Непредвиденная ошибка", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            CreateDiana(out pDiana);
            if (pDiana == IntPtr.Zero)
            {
                return;
            }

            OnDataReceived = DataReceivedCallback;
            SetDataReceivedCallback(pDiana, 0, OnDataReceived);

            OnConnectionChanged = ConnectionChangedCallback;
            SetConnectionChangedCallback(pDiana, 0, OnConnectionChanged);

            OnDianaInfo = DianaInfoCallback;
            SetDianaInfoCallback(pDiana, 0, OnDianaInfo);

            OnOptionalTypeChanged = OptionalTypeChangedCallback;
            SetOptionalTypeChangedCallback(pDiana, 0, OnOptionalTypeChanged);

            UpdateDeviceList();
        }
        public void Open()
        {
            DataReceivedCallback callback = new DataReceivedCallback(OnDataReceived);
            if (listenSockets != null)
            {
                socketListener = new UdpSocketListener(this.listenSockets,
                    this.maxBufferSize, this.maxMessageSize, callback);
            }
            else
            {
                IPAddress address = IPAddress.Broadcast;
                if (this.ListenUri.HostNameType == UriHostNameType.IPv4 || this.ListenUri.HostNameType == UriHostNameType.IPv6)
                {
                    address = IPAddress.Parse(this.ListenUri.DnsSafeHost);
                }

                socketListener = new UdpSocketListener(address, this.ListenUri.Port, this.multicast,
                    this.maxBufferSize, this.maxMessageSize, callback);
            }

            socketListener.Open();
        }
Exemplo n.º 12
0
        /// <summary>
        /// A connection to our server, always listening asynchronously.
        /// </summary>
        /// <param name="socket">The Socket for the connection.</param>
        /// <param name="args">The SocketAsyncEventArgs for asyncronous recieves.</param>
        /// <param name="dataReceived">A callback invoked when data is recieved.</param>
        /// <param name="disconnectedCallback">A callback invoked on disconnection.</param>
        public NetConnection(Socket socket, SocketAsyncEventArgs args, DataReceivedCallback dataReceived,
                             DisconnectedCallback disconnectedCallback, T session)
        {
            lock (this)
            {
                this.packageHandler = new PackageHandler <NetConnection <T> >(this);
                State state = new State()
                {
                    socket               = socket,
                    dataReceived         = dataReceived,
                    disconnectedCallback = disconnectedCallback
                };
                eventArgs = new SocketAsyncEventArgs();
                eventArgs.AcceptSocket = socket;
                eventArgs.Completed   += ReceivedCompleted;
                eventArgs.UserToken    = state;
                eventArgs.SetBuffer(new byte[64 * 1024], 0, 64 * 1024);

                BeginReceive(eventArgs);
                this.session = session;
            }
        }
Exemplo n.º 13
0
        public void Open()
        {
            DataReceivedCallback callback = new DataReceivedCallback(OnDataReceived);

            if (listenSockets != null)
            {
                socketListener = new UdpSocketListener(this.listenSockets,
                                                       this.maxBufferSize, this.maxMessageSize, callback);
            }
            else
            {
                IPAddress address = IPAddress.Broadcast;
                if (this.ListenUri.HostNameType == UriHostNameType.IPv4 || this.ListenUri.HostNameType == UriHostNameType.IPv6)
                {
                    address = IPAddress.Parse(this.ListenUri.DnsSafeHost);
                }

                socketListener = new UdpSocketListener(address, this.ListenUri.Port, this.multicast,
                                                       this.maxBufferSize, this.maxMessageSize, callback);
            }

            socketListener.Open();
        }
Exemplo n.º 14
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="client">Asyncronous REST client instance</param>
 /// <param name="callback">Callback to be invoked on data retrieved</param>
 /// <param name="intervalMs">Polling interval, in milliseconds.</param>
 public PollingClient(Client client, DataReceivedCallback callback, int intervalMs)
 {
     geoJsonClient = client;
     this.callback = callback;
     clientTimer   = new Timer(onTimerTick, null, 0, intervalMs);
 }
Exemplo n.º 15
0
 public UdpListenerManager(DataReceivedCallback dataReceivedCallback)
 {
     listeners = new Dictionary<IPEndPoint, UdpSocketListener>();
     this.dataReceivedCallback = dataReceivedCallback;
 }
Exemplo n.º 16
0
 internal static extern int SetDataReceivedCallback(DataReceivedCallback callback, IntPtr userData);
 public HostedUdpTransportListener(int instanceId, Uri uri, DataReceivedCallback dataReceivedCallback)
 {
     this.instanceId = instanceId;
     this.uri = uri;
     this.dataReceivedCallback = dataReceivedCallback;
 }
 public HostedUdpTransportListener(int instanceId, Uri uri, DataReceivedCallback dataReceivedCallback)
 {
     this.instanceId           = instanceId;
     this.uri                  = uri;
     this.dataReceivedCallback = dataReceivedCallback;
 }
Exemplo n.º 19
0
 public UdpListenerManager(DataReceivedCallback dataReceivedCallback)
 {
     listeners = new Dictionary <IPEndPoint, UdpSocketListener>();
     this.dataReceivedCallback = dataReceivedCallback;
 }
Exemplo n.º 20
0
 public static extern void SetDataReceivedCallback(IntPtr pDiana, UInt32 dwUser, DataReceivedCallback pCallback);
Exemplo n.º 21
0
 private void Exporter_DataReceived(object sender, DataReceivedEventArgs e)
 {
     if (e.Data == null) return;
     if (consoleBox.InvokeRequired)
     {
         var callback = new DataReceivedCallback(Exporter_DataReceived);
         BeginInvoke(callback, new object[] { null, e });
     }
     else
         consoleBox.AppendText(e.Data + "\n");
 }