// returns true if this was the last entry
        public void Unsubscribe(IPAddress sourceAddress, IPAddress destAddress, SocketDataReceivedEventHandler callback)
        {
            lock (addressEntries) {
                int addressCount = 0;
                bool isMulticast = IsMulticast(destAddress);
                bool isBroadcast = IsBroadcast(destAddress);
                bool isSpecialAddress = isMulticast || isBroadcast;

                int removeIndex = -1;

                for (int i = 0; i < addressEntries.Count; i++) {
                    AddressEntry entry = addressEntries[i];
                    if (entry.callback.Equals(callback) && entry.sourceAddress.Equals(sourceAddress) && entry.destAddress.Equals(destAddress)) {
                        removeIndex = i;
                    }
                    else {
                        if (isSpecialAddress && entry.destAddress.Equals(destAddress)) {
                            addressCount++;
                        }
                    }
                }

                if (removeIndex != -1) {
                    addressEntries.RemoveAt(removeIndex);
                    if (isMulticast && addressCount == 0) {
                        // remove the multicast address
                        socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.DropMembership, new MulticastOption(destAddress));
                    }
                    else if (isBroadcast && addressCount == 0) {
                        socket.EnableBroadcast = false;
                    }
                }
            }
        }
        // set source to any to receive from any source address, otherwise will only report those source addresses that match
        // set dest to any to receive data for any destination address, localhost to get only packets destined to the local
        //   unicast address, set to any other address (including multicast, broadcast) to get packets for only that destination
        public void Subscribe(IPAddress sourceAddress, IPAddress destAddress, SocketDataReceivedEventHandler callback)
        {
            AddressEntry entry = new AddressEntry(sourceAddress, destAddress, callback);

            lock (addressEntries) {
                // determine if this is a multicast destination
                if (IsMulticast(destAddress)) {
                    // it is, so join the group if we aren't already in it
                    bool inGroup = false;
                    foreach (AddressEntry ent in addressEntries) {
                        if (ent.destAddress.Equals(destAddress)) {
                            inGroup = true;
                        }
                    }

                    if (!inGroup) {
                        socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(destAddress));
                    }
                }

                if (IsBroadcast(destAddress)) {
                    if (!socket.EnableBroadcast) {
                        socket.EnableBroadcast = true;
                    }
                }

                // add to the list of address entries
                addressEntries.Add(entry);
            }
        }
예제 #3
0
        public void CloseCall()
        {
            this.isUdpConnectionMapped = false;

            this.udpReceiver.StopReceiver();
            this.udpReceiver.SocketDataReceived -= udpReceiver_SocketDataReceived;

            this.callHelper.CloseCall();
            this.callHelper.DataAvailable -= callHelper_DataAvailable;
        }
예제 #4
0
        public void CloseCall(string receiver, string sender, string id)
        {
            if (this.callHelper != null && this.callHelper.IsCallEstablished)
            {
                this.isUdpConnectionMapped = false;

                this.udpReceiver.StopReceiver();
                this.udpReceiver.SocketDataReceived -= udpReceiver_SocketDataReceived;

                this.callHelper.CloseCall();
                this.callHelper.DataAvailable -= callHelper_DataAvailable;

                this.SendMessage(receiver, id, sender, "/call/close");
            }
        }
예제 #5
0
        // returns true if this was the last entry
        public void Unsubscribe(IPAddress sourceAddress, IPAddress destAddress, SocketDataReceivedEventHandler callback)
        {
            lock (addressEntries) {
                int  addressCount     = 0;
                bool isMulticast      = IsMulticast(destAddress);
                bool isBroadcast      = IsBroadcast(destAddress);
                bool isSpecialAddress = isMulticast || isBroadcast;

                int removeIndex = -1;

                for (int i = 0; i < addressEntries.Count; i++)
                {
                    AddressEntry entry = addressEntries[i];
                    if (entry.callback.Equals(callback) && entry.sourceAddress.Equals(sourceAddress) && entry.destAddress.Equals(destAddress))
                    {
                        removeIndex = i;
                    }
                    else
                    {
                        if (isSpecialAddress && entry.destAddress.Equals(destAddress))
                        {
                            addressCount++;
                        }
                    }
                }

                if (removeIndex != -1)
                {
                    addressEntries.RemoveAt(removeIndex);
                    if (isMulticast && addressCount == 0)
                    {
                        // remove the multicast address
                        socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.DropMembership, new MulticastOption(destAddress));
                    }
                    else if (isBroadcast && addressCount == 0)
                    {
                        socket.EnableBroadcast = false;
                    }
                }
            }
        }
예제 #6
0
        // set source to any to receive from any source address, otherwise will only report those source addresses that match
        // set dest to any to receive data for any destination address, localhost to get only packets destined to the local
        //   unicast address, set to any other address (including multicast, broadcast) to get packets for only that destination
        public void Subscribe(IPAddress sourceAddress, IPAddress destAddress, SocketDataReceivedEventHandler callback)
        {
            AddressEntry entry = new AddressEntry(sourceAddress, destAddress, callback);

            lock (addressEntries) {
                // determine if this is a multicast destination
                if (IsMulticast(destAddress))
                {
                    // it is, so join the group if we aren't already in it
                    bool inGroup = false;
                    foreach (AddressEntry ent in addressEntries)
                    {
                        if (ent.destAddress.Equals(destAddress))
                        {
                            inGroup = true;
                        }
                    }

                    if (!inGroup)
                    {
                        socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(destAddress));
                    }
                }

                if (IsBroadcast(destAddress))
                {
                    if (!socket.EnableBroadcast)
                    {
                        socket.EnableBroadcast = true;
                    }
                }

                // add to the list of address entries
                addressEntries.Add(entry);
            }
        }
 public AddressEntry(IPAddress sourceAddress, IPAddress destAddress, SocketDataReceivedEventHandler callback)
 {
     this.sourceAddress = sourceAddress;
     this.destAddress = destAddress;
     this.callback = callback;
 }
예제 #8
0
 public AddressEntry(IPAddress sourceAddress, IPAddress destAddress, SocketDataReceivedEventHandler callback)
 {
     this.sourceAddress = sourceAddress;
     this.destAddress   = destAddress;
     this.callback      = callback;
 }