private async void OnPanelLoaded(object sender, RoutedEventArgs e)
        {
            List <SerialPort> ports = new List <SerialPort>(await SerialPort.FindPorts());

            if (!unloaded)
            {
                foreach (var port in ports)
                {
                    SerialPorts.Items.Add(port);
                }
            }

            NetworkList.Items.Add(new NetworkModel()
            {
                Network     = null,
                Name        = "localhost",
                Description = "Connect to an app on your local computer"
            });

            foreach (var network in UdpPort.GetLocalAddresses())
            {
                NetworkList.Items.Add(new NetworkModel()
                {
                    Network     = network,
                    Name        = network.Name,
                    Description = network.Description
                });
            }
            EnableButtons();
        }
Exemple #2
0
        public override Dictionary <string, string> ToDict()
        {
            var dict = new Dictionary <string, string>
            {
                { "serviceName", ServiceName },
                { "udpPort", UdpPort.ToString() },
            };

            if (!string.IsNullOrWhiteSpace(NamespaceId))
            {
                dict.Add("namespaceId", NamespaceId);
            }

            if (!string.IsNullOrWhiteSpace(Clusters))
            {
                dict.Add("clusters", Clusters);
            }

            if (!string.IsNullOrWhiteSpace(GroupName))
            {
                dict.Add("groupName", GroupName);
            }

            if (HealthyOnly.HasValue)
            {
                dict.Add("healthyOnly", HealthyOnly.Value.ToString());
            }

            if (!string.IsNullOrWhiteSpace(ClientIp))
            {
                dict.Add("clientIP", ClientIp);
            }

            return(dict);
        }
Exemple #3
0
        public bool Equals(PeerSocketAddress other)
        {
            var t1 = InetAddress.Equals(other.InetAddress);
            var t2 = TcpPort.Equals(other.TcpPort);
            var t3 = UdpPort.Equals(other.UdpPort);

            return(t1 && t2 && t3);
        }
Exemple #4
0
    public override int GetHashCode()
    {
        var hashCode = 1749498485;

        hashCode = hashCode * -1521134295 + EqualityComparer <IPAddress> .Default.GetHashCode(Address);

        hashCode = hashCode * -1521134295 + UdpPort.GetHashCode();
        hashCode = hashCode * -1521134295 + TcpPort.GetHashCode();
        return(hashCode);
    }
Exemple #5
0
 public void applyConfiguration()
 {
     config.AppSettings.Settings["nomeServer"].Value      = ServerName;
     config.AppSettings.Settings["password"].Value        = Password;
     config.AppSettings.Settings["indirizzo"].Value       = Address;
     config.AppSettings.Settings["portTCP"].Value         = TcpPort.ToString();
     config.AppSettings.Settings["portUDP"].Value         = UdpPort.ToString();
     config.AppSettings.Settings["enableUDP"].Value       = UdpEnabled.ToString();
     config.AppSettings.Settings["passwordEnabled"].Value = PasswordEnabled.ToString();
 }
        public Boolean InitUdp()
        {
            try
            {
                if (UdpPort == 0)
                {
                    //udpClient = new UdpClient(new IPEndPoint(UdpIP, UdpPort)
                    if (!GetSinglePort())
                    {
                        throw new SocketException();
                    }
                }
                else
                {
                    if (UdpIP != null)
                    {
                        udpClient = new UdpClient(new IPEndPoint(UdpIP, UdpPort));  //绑定IP和端口
                    }
                    else
                    {
                        udpClient = new UdpClient(UdpPort);  //绑定端口
                    }
                }
                //udpClient.Client.SetSocketOption(SocketOptionLevel.Socket,
                //        SocketOptionName.ReuseAddress, true);
                udpClient.Client.ReceiveBufferSize = 20 * 1024;
                udpClient.Client.SendBufferSize    = 20 * 1024;
                //设置为非阻塞模式
                //主要应用于大批量终端信息传输
                if (IsNotBlock)
                {
                    udpClient.Client.Blocking = false;
                }

                if (TimeOut > 0)
                {
                    udpClient.Client.ReceiveTimeout = TimeOut * 1000;
                }
                LockRecObject = new Object();
                arrReceive    = new List <string>();
                listRecByte   = new List <byte>();
            }
            catch (SocketException exsc)
            {
                System.Windows.Forms.MessageBox.Show("端口" + UdpPort.ToString() + "错误:" + exsc.Message, "错误");
                return(false);
            }
            catch (Exception ex)
            {
                Console.WriteLine("InitUdp:" + ex.Message);
                return(false);
            }
            return(true);
        }
 public static void SaveSetting()
 {
     reader.SetNodeText("PingTimeout", PingTimeout.ToString());
     reader.SetNodeText("RequestTimeout", RequestTimeout.ToString());
     reader.SetNodeText("TcpPort", TcpPort.ToString());
     reader.SetNodeText("UdpPort", UdpPort.ToString());
     reader.SetNodeText("ClientPort", ClientPort.ToString());
     reader.SetNodeText("Adapter", Adapter);
     reader.SetNodeText("PlayerID", PlayerID);
     reader.SetNodeText("DataMode", dataMode);
     reader.SetNodeText("SyncMode", syncMode);
     reader.Save("setting.xml");
 }
        private void OnUdpConnect(object sender, RoutedEventArgs e)
        {
            if (port != null)
            {
                port.Close();
                port = null;
                OnPortClosed();
            }
            else
            {
                var       model = (NetworkModel)NetworkList.SelectedItem;
                IPAddress addr  = null;
                if (model.Network != null)
                {
                    foreach (UnicastIPAddressInformation ip in model.Network.GetIPProperties().UnicastAddresses)
                    {
                        if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                        {
                            addr = ip.Address;
                        }
                    }
                }
                else
                {
                    addr = IPAddress.Parse("127.0.0.1");
                }

                int i = 0;
                if (int.TryParse(PortNumber.Text, out i))
                {
                    try
                    {
                        var udp = new UdpPort();
                        udp.Connect(new IPEndPoint(addr, i), null);
                        OnPortConnected(udp);
                        UdpConnectButton.Content = "Disconnect";
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error Connectin", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }
Exemple #9
0
        public void Generate(XmlWriter writer)
        {
            writer.WriteStartElement(@"mediaRelay");

            writer.WriteElementString(@"location", Common.ToString(Location));

            if (string.IsNullOrEmpty(HostName) == false)
            {
                writer.WriteElementString(@"hostName", HostName);
            }
            else
            {
                writer.WriteElementString(@"directIPAddress", DirectIpAddress);
            }

            writer.WriteElementString(@"udpPort", UdpPort.ToString());
            writer.WriteElementString(@"tcpPort", TcpPort.ToString());

            writer.WriteEndElement();
        }
Exemple #10
0
 private void WriteSettings(XmlWriter writer)
 {
     writer.WriteStartElement("Settings");
     writer.WriteAttributeString("Version", 1.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteElementString("MusicDirectory", MusicDirectory);
     writer.WriteElementString("SoundsDirectory", SoundDirectory);
     writer.WriteElementString("LastDownloadLocation", LastDownloadLocation);
     writer.WriteStartElement("WindowLayout");
     writer.WriteRaw(WindowLayout);
     writer.WriteEndElement();
     writer.WriteStartElement("Volumes");
     writer.WriteAttributeString("Overall", GlobalVolume.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteAttributeString("Music", MusicVolume.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteAttributeString("Sound", SoundVolume.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteEndElement();
     writer.WriteStartElement("Network");
     writer.WriteAttributeString("TcpPort", TcpPort.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteAttributeString("UdpPort", UdpPort.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteAttributeString("IPAddress", IPAddress);
     writer.WriteAttributeString("CheckForUpdate", CheckForUpdate ? "true" : "false");
     writer.WriteAttributeString("Enabled", UseLegacyNetwork ? "true" : "false");
     writer.WriteAttributeString("WebTcpPort", WebTcpPort.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteAttributeString("UseWebNetwork", UseWebNetwork ? "true" : "false");
     writer.WriteEndElement();
     RecentFiles.WriteFiles(writer);
     writer.WriteStartElement("Tools");
     writer.WriteElementString("SoundFileEditor", SoundFileEditor);
     writer.WriteElementString("ExternalMusicPlayer", ExternalMusicPlayer);
     writer.WriteEndElement();
     writer.WriteStartElement("Options");
     writer.WriteAttributeString("MessageFilterLevel", MessageFilterLevel.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteAttributeString("ShowKeys", ShowKeysInButtons ? "true" : "false");
     writer.WriteAttributeString("GlobalKeyHook", GlobalKeyHook ? "true" : "false");
     writer.WriteAttributeString("OutputDevice", OutputDeviceIndex.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteEndElement();
     writer.WriteStartElement("Streaming");
     writer.WriteAttributeString("Active", UseStreaming ? "true" : "false");
     writer.WriteAttributeString("Address", StreamingServerAddress);
     writer.WriteAttributeString("Port", StreamingServerPort.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteAttributeString("Password", StreamingPassword);
     writer.WriteAttributeString("Encoding", StreamingEncoder.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteAttributeString("StreamName", StreamingStreamName);
     writer.WriteAttributeString("Bitrate", StreamingBitrate.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteAttributeString("UserName", StreamingUserName);
     writer.WriteEndElement();
     writer.WriteStartElement("OnlineDB");
     writer.WriteAttributeString("UserId", OnlineDBUserId);
     writer.WriteAttributeString("DialogAfterDownload", ShowDialogAfterDownload ? "true" : "false");
     writer.WriteAttributeString("DialogAfterUpload", ShowDialogAfterUpload ? "true" : "false");
     writer.WriteEndElement();
     writer.WriteStartElement("TagMusicFading");
     writer.WriteAttributeString("FadeTime", TagMusicFadeTime.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteAttributeString("FadeOnlyOnChange", TagMusicFadeOnlyOnChange ? "true" : "false");
     writer.WriteEndElement();
     writer.WriteStartElement("Music");
     writer.WriteAttributeString("PlayOnAllSpeakers", PlayMusicOnAllSpeakers ? "true" : "false");
     writer.WriteAttributeString("ButtonFadeMode", ButtonMusicFadeMode.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteAttributeString("ButtonFadeTime", ButtonMusicFadeTime.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteEndElement();
     writer.WriteStartElement("Controllers");
     writer.WriteAttributeString("LocalPlayerPath", LocalPlayerPath);
     writer.WriteEndElement();
     writer.WriteStartElement("TipOfTheDay");
     writer.WriteAttributeString("ShowTip", ShowTipOfTheDay ? "true" : "false");
     writer.WriteAttributeString("LastTip", LastTipOfTheDay.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteEndElement();
     writer.WriteStartElement("Tpm2NetTarget");
     writer.WriteAttributeString("Host", Tpm2NetTargetHost);
     writer.WriteAttributeString("Port", Tpm2NetTargetPort.ToString(System.Globalization.CultureInfo.InvariantCulture));
     writer.WriteEndElement();
     writer.WriteEndElement();
 }
Exemple #11
0
 public override string ToString()
 {
     return(IP.ToString() + ":" + TcpPort.ToString() + ":" + UdpPort.ToString());;
 }
 public Mount()
 {
     port  = new UdpPort();
     axis1 = new Axis(1, port);
     axis2 = new Axis(2, port);
 }