Home Forums Support Peer Discovery Issue on Mac Os

Viewing 8 posts - 11 through 18 (of 18 total)
  • Author
    Posts
  • #3372
    Anonymous
    Inactive

    We are still investigating this. We were not able to reproduce any problems in OSX. Will post back here when we have more.

    #3376
    Anonymous
    Inactive

    Udp broadcast peer discovery sample doesn’t work on latest MacOs/Ubuntu. I don’t know how are you not able to reproduce any problems. Are you telling me that it works? It works only on Windows.
    Anyway I already wrote udp broadcast peer discovery myself.

    #3380
    Anonymous
    Inactive

    iYalovoy, Can you share the code or technique for your custom Udp peer discovery?

    #3388
    Anonymous
    Inactive

    Hi mark,

    public class UdpDiscovery :  IDisposable
    	{
    		private ILog _log;
    		private UdpClient _client;
    		IPEndPoint _localpt;
    		int _broadcastPort = 8888;
    		UdpClient _server;
    		bool _requestStop;
    
    		public UdpDiscovery (ILog log)
    		{
    			_log = log;
    
    			//Create socket for broadcasting udp packets
    			_localpt = new IPEndPoint (IPAddress.Any, 0);
    			_client = new UdpClient ();
    			_client.Client.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
    			_client.Client.Bind (_localpt);
    			_client.EnableBroadcast = true;
    
    			//Server side
    			var point = new IPEndPoint (IPAddress.Any, _broadcastPort);
    			_server = new UdpClient ();
    			_server.ExclusiveAddressUse = false;
    			_server.Client.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
    			_server.Client.Bind (point);
    		}
    
    		public void Signal (byte[] data)
    		{
    			_client.Send (data, data.Length, new IPEndPoint (IPAddress.Broadcast, _broadcastPort));
    		}
    
    		public void StartDiscover ()
    		{
    			_requestStop = false;
    			var handle = _server.BeginReceive (new AsyncCallback (DataReceived), null);
    		}
    
    		public void StopDiscovery ()
    		{
    			_requestStop = true;
    		}
    
    		public event EventHandler<EventArgs<byte[]>> PeerDiscovered;
    
    		void OnPeerDiscovered (byte[] address)
    		{
    			if (PeerDiscovered != null)
    				PeerDiscovered (this, new EventArgs<byte[]> (address));
    		}
    
    		void DataReceived (IAsyncResult ar)
    		{
    			var clientEp = new IPEndPoint (IPAddress.Any, 0);
    			var data = _server.EndReceive (ar, ref clientEp);		
    
    			OnPeerDiscovered (data);
    
    			if (!_requestStop)
    				_server.BeginReceive (new AsyncCallback (DataReceived), null);
    		}
    
    		public void Dispose ()
    		{
    			_client.Close ();
    			_server.Close ();
    		}
    	}

    You call Signal on peer as often as you want. For example:

    ThreadPool.QueueUserWorkItem ((o) => {
    					while (true) {
    						discovery.Signal (data);
    						Thread.Sleep (1000);
    					}
    				});

    To discover peer first call StartDiscover and subscribe to event PeerDiscovered. As soon as peer discoverd you event handler would be called and you can process you data.
    Keep in mind that data shouldn’t be large than udp packet size.
    Good luck!

    #3391
    Anonymous
    Inactive

    iYalovoy,

    That code was very helpful thanks. The only issue that I ran into was using IPAddress.Any on the client did not work for me on all computers. If the computer has multiple ipv4 interfaces it will use the first one and not any others. I had to create separate clients for each ipv4 interface and send the data. Not a big deal, but it did take me a while to figure out. Might this be an issue with networkcomms’ product? I don’t have the source to find out.

    #3392
    Anonymous
    Inactive

    Hey Mark,

    The only issue that I ran into was using IPAddress.Any on the client did not work for me on all computers. If the computer has multiple ipv4 interfaces it will use the first one and not any others. I had to create separate clients for each ipv4 interface and send the data. Not a big deal

    Yeah, I am aware of that. Wasn’t the part of sample, but as expected you figured it out yourself.

    Might this be an issue with networkcomms’ product?

    No, it is not. I have source code.

    I am glad that it helped you.

    #3393
    Anonymous
    Inactive

    Heya iYalovoy,

    Thank you for providing some independant verification that NetworkComms.Net is not the primary issue here. Unfortunately, and this is something we have dealt with in the past, networking can be VERY os specific. As such an implementation that works on one may not work on the other. These are also amongst the most tricky problems to solve without potentially breaking something else. We can only apologise again for the delay in finding a comprehensive solution to this problem, we understand how frustrating these issues can be. We are working on this issue, amongst others, and hope to have a suitable fix soon.

    Regards,
    Marc

    #3396
    Anonymous
    Inactive

    Heya Mark,

    Glad that it helps.
    Peer discovery is standalone feature, so it doesn’t ruin the rest of the library.

    Regards,
    Igor.

Viewing 8 posts - 11 through 18 (of 18 total)
  • You must be logged in to reply to this topic.