Tcp Socket не подключается - PullRequest
       37

Tcp Socket не подключается

0 голосов
/ 24 сентября 2019

У меня есть следующий код:

Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Try
                Dim reply As String = "v1.0"
                If reply <> S_Settings.StubVer Then
                    S_Messages.Messages("{ New update is available! }", "Get to me")
                ElseIf reply = S_Settings.StubVer Then
                    S_Messages.Messages("{ You are using the latest version! }", "Bugs :Contact me")
                End If
        Catch ex As Exception
        End Try


        Dim Client As Net.Sockets.TcpClient = Nothing
        Dim PortLabel As New Text.StringBuilder
        For Each ThePort In S_Settings.PORT
            Try
                If GetExternalAddress() = "127.0.0.1" Then
                    PortLabel.Append(String.Format(" {0}=OPENED ", ThePort))
                    MetroLabel3.Text = String.Format("IP={0} {1} KEY={2}", GetExternalAddress, PortLabel.ToString, "abcd")
                    MetroLabel3.ForeColor = Color.Lime
                Else
                    Client = New Net.Sockets.TcpClient
                    Client.Connect(GetExternalAddress, ThePort)
                    PortLabel.Append(String.Format(" {0}=OPENED ", ThePort))
                    MetroLabel3.Text = String.Format("IP={0} {1} KEY={2}", GetExternalAddress, PortLabel.ToString, "abcd")
                    MetroLabel3.ForeColor = Color.Lime
                End If
            Catch ex As Net.Sockets.SocketException
                MessageBox.Show(ex.ToString() + " 1")
                MetroProgressSpinner1.Spinning = False
                PortLabel.Append(String.Format(" {0}=CLOSED ", ThePort))
                MetroLabel3.Text = String.Format("IP={0}  {1}  KEY={2}", GetExternalAddress, PortLabel.ToString, "abcd")
                MetroLabel3.ForeColor = Color.Red
                'Try : My.Computer.Audio.Play(My.Resources._Error, AudioPlayMode.Background) : Catch : End Try 'https://freesound.org/people/eardeer/sounds/385281/

                If GTV("FW") = Nothing Then
                    Dim result As DialogResult = MessageBox.Show("Port " & ThePort & " seems to be blocked" + Environment.NewLine + "Do you want to add myProg into firewall exception", "", MessageBoxButtons.YesNo)
                    If result = DialogResult.Yes Then
                        Try
                            STV("FW", "1")
                            Dim process As New Process()
                            process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
                            process.StartInfo.FileName = "cmd.exe"
                            process.StartInfo.UseShellExecute = True
                            process.StartInfo.Verb = "runas"
                            process.StartInfo.Arguments = "/c netsh advfirewall firewall add rule name=""myProg"" dir=in action=allow program=""" & Application.ExecutablePath & """ enable=yes"
                            process.Start()
                            process.WaitForExit()
                            Process.Start(Application.ExecutablePath)
                            End
                        Catch ex1 As Exception
                            MessageBox.Show(ex1.ToString() + " 2")
                        End Try
                    End If
                End If
            Finally
                Try : Client.Close() : Catch : End Try
            End Try
        Next

    End Sub

Я получаю следующее исключение и не знаю, как его разрешить: exception images

Почемупорт не подключается?Я отключил весь брандмауэр.Дайте мне знать, что я могу сделать.

...