Tagged: Mac Os, Mono, Peer Discovery
- This topic has 17 replies, 3 voices, and was last updated 10 years, 2 months ago by Anonymous.
-
AuthorPosts
-
September 30, 2014 at 22:35 #3372AnonymousInactive
We are still investigating this. We were not able to reproduce any problems in OSX. Will post back here when we have more.
October 1, 2014 at 05:23 #3376AnonymousInactiveUdp 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.October 1, 2014 at 15:05 #3380AnonymousInactiveiYalovoy, Can you share the code or technique for your custom Udp peer discovery?
October 3, 2014 at 08:10 #3388AnonymousInactiveHi 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!October 6, 2014 at 22:10 #3391AnonymousInactiveiYalovoy,
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.
October 7, 2014 at 05:30 #3392AnonymousInactiveHey 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.
October 7, 2014 at 22:20 #3393AnonymousInactiveHeya 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,
MarcOctober 8, 2014 at 05:34 #3396AnonymousInactiveHeya Mark,
Glad that it helps.
Peer discovery is standalone feature, so it doesn’t ruin the rest of the library.Regards,
Igor. -
AuthorPosts
- You must be logged in to reply to this topic.