Пример #1
0
 public static NetWorker GetInstance()
 {
     if (_instance != null)
     {
         return _instance;
     }
     _instance = new NetWorker
     {
         _udpClient = new UdpClient(GetIntParamFromConfig("LocalPort"))
         {
             EnableBroadcast = true,
             MulticastLoopback = false
         }
     };
     _instance._udpClient.JoinMulticastGroup(GetGroupAddress(), GetIntParamFromConfig("TTL"));
     return _instance;
 }
Пример #2
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         this.Hide();
         var loginForm = new LoginForm();
         if (loginForm.ShowDialog() == true)
         {
             SessionParams.CurrentUser = new User(SessionParams.GetLocalIpAddress(), loginForm.Nikname);
             this.Title = String.Format("P2PChat [{0}]", SessionParams.CurrentUser.Name);
             _netWorker = NetWorker.GetInstance();
             _netWorker.StartListening(ms =>
             {
                 if (ms.SystemMessage)
                     RefreshUserList(ms);
                 else
                     AddMessageToChat(ms);
             });
             _netWorker.StartSendingAvailabilityMessage();
             this.Show();
         }
         else
             this.Close();
     }
     catch (Exception ex)
     {
         DisplayError(ex);
     }
 }