public void GetMcastData(object ipd) { try { IpDetails ipConf = (IpDetails)ipd; byte[] byt = new byte[1024]; //Socket s; s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); s.ExclusiveAddressUse = false; s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); IPEndPoint ipep = new IPEndPoint(IPAddress.Any, Convert.ToInt32(ipConf.Port)); s.Bind(ipep); IPAddress ip = IPAddress.Parse(ipConf.McastIp.Trim()); s.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(ip, IPAddress.Parse(ipConf.LocalIp))); while (true) { try { int size = s.Receive(byt); // MessageBox.Show("DAta Recv " + size.ToString()); //break; if (size > 0) { if (DataArrival != null) { DataArrival(byt); } } } catch (Exception e) { if (Sock_Error != null) { Sock_Error(e.Message.ToString()); } } } } catch (Exception ex) { if (Sock_Error != null) { Sock_Error(ex.Message.ToString()); } } }
public void updateMyProfile(string mac, string name, string dpPath) { if (myProfile == null) { myProfile = new Contact(); } myProfile.name = name; myProfile.mac = mac; myProfile.displayProfile = dpPath; myProfile.currentIp = IpDetails.getInstance().getMyLocalIp(); StorageHandler.updateMyContactsFile(this); //sendMyContactToAll(); }
public void isConnectedToNetworkTest() { Console.WriteLine(IpDetails.getInstance().isConnectedToNetwork()); }