Exemplo n.º 1
0
 public static void CloseOtherConnections(SocketConnection notClosed)
 {
     if (!connectionsCreated)
     {
         return;
     }
     Thread notClosedThread = null;
     if (notClosed != null)
     {
         notClosedThread = connections[notClosed];
     }
     foreach (var item in connections)
     {
         if (item.Key != notClosed)
         {
             try
             {
                 item.Key.CloseNotBinded();
                 Logger.Log("zamknieto polaczenie w CloseOtherConnections");
             }
             catch (Exception)
             {
                 Logger.Log("zamknieto polaczenie w CloseOtherConnections");
             }
         }
     }
       //  clients = connections.Count - 1;
     if (notClosed == null)
     {
         clients = 0;
     }
     connections.Clear();
     if (notClosed != null)
     {
         connections.Add(notClosed, notClosedThread);
     }
     connectionsCreated = false;
     connectedLock.Set();
 }
Exemplo n.º 2
0
        public static string CreateConnection()
        {
            connectionsCreated = true;
            connectedLock.Reset();
            List<IPAddress> ips = new List<IPAddress>();
            foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (nic.OperationalStatus == OperationalStatus.Up)
                {
                    foreach (UnicastIPAddressInformation ip in nic.GetIPProperties().UnicastAddresses)
                    {
                        if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                        {
                            ips.Add(ip.Address);
                        }
                    }
                }
            }

            string result = "";
            foreach (var ipAddress in ips)
            {
                SocketConnection tmpSocket = new SocketConnection(ipAddress, ConnectionPort);
                Thread tmpThread = new Thread(delegate() {
                    try
                    {
                        tmpSocket.StartListening();
                    }
                    catch (SocketException)
                    {
                        Logger.Log("zamknieto watek");
                    }

                });
                tmpThread.Start();
                connections.Add(tmpSocket,tmpThread);
                result += ipAddress.ToString() +":"+ConnectionPort+ ";";
            }
            result=result.Remove(result.LastIndexOf(";"));
            return result;
        }
Exemplo n.º 3
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                interpreter.BeginProccessing();
                qrString = SocketConnection.CreateConnection();

                myInstance.Dispatcher.Invoke(new Action(delegate()
                {
                    window = new QRWindow();
                        window.qrControl.Text = qrString;
                        window.Show();
                    }));
                connection = SocketConnection.GetConnectedSocket();
                myInstance.Dispatcher.Invoke(new Action(delegate() { window.Close();}));
            }
            catch (Exception ex)
            {
                Logger.Log(ex.ToString());
                return;
            }
        }