已经运行的应用程序现在获得套接字错误10013

E_B*_*lue 8 sockets vb.net

我在VB.NET中完成了一个应用程序,它监听特定的UDP端口并通过相同的端口回复发送数据包的IP.它从几年到上个月都运行良好; 现在当尝试通过套接字错误10013应答崩溃时.

我甚至尝试使用旧版本,我知道它也在工作并且同样崩溃.

我尝试禁用Microsoft Security Essentials实时保护和Windows防火墙,但无法正常工作.

在代码我有线

MyUdpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, True)
Run Code Online (Sandbox Code Playgroud)

我不知道该怎么做,我迷路了.

不知道怎么解决这个问题?

编辑: 这是代码

#Region "UDP Send variables"
   Dim GLOIP As IPAddress
   Dim GLOINTPORT As Integer
   Dim bytCommand As Byte() = New Byte() {}
#End Region

Dim MyUdpClient As New UdpClient()

Private Sub StartUdpBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartUdpBtn.Click
      If StartUdpBtn.Tag = 0 Then
          '   If Not UdpOpen Then
          StartUdpReceiveThread(CInt(ListeningPortLbl.Text))
          'End If
      Else
          If ThreadReceive.IsAlive Then
              ThreadReceive.Abort()
              MyUdpClient.Close()
              PrintLog("UDP port closed")
              StartUdpBtn.Tag = 0
              UdpOpen = False
              StartUdpBtn.Text = "Start UDP"
          End If
      End If

      If UdpOpen Then
          StartUdpBtn.Tag = 1
          StartUdpBtn.Text = "Stop UDP"
      Else
          StartUdpBtn.Tag = 0
          StartUdpBtn.Text = "Start UDP"
          TimerUDP.Enabled = False
          TiempoUDP.Stop()
          TiempoUdpLbl.Text = "--:--:--"
      End If

  End Sub

Private Sub StartUdpReceiveThread(ByVal Port As Integer)
    Dim UdpAlreadyOpen As Boolean = False
    Try
        If Not UdpOpen Then
            MyUdpClient = New UdpClient(Port)
            MyUdpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, True)
            UdpAlreadyOpen = True
        Else
            Me.Invoke(Sub()
                          TiempoUDP.Restart()
                          If TimerUDP.Enabled = False Then
                              TimerUDP.Enabled = True
                          End If
                      End Sub)
        End If

        ThreadReceive = New System.Threading.Thread(AddressOf UdpReceive)
        ThreadReceive.IsBackground = True

        ThreadReceive.Start()
        UdpOpen = True

        If UdpAlreadyOpen Then 
                PrintLog(String.Format("UDP port {0} opened, waiting data...", Port.ToString))
        End If
    Catch ex As Exception
        PrintErrorLog(ex.Message)
        PrintErrorLog(ex.StackTrace)
    End Try
End Sub

Private Sub UdpReceive()
    Dim receiveBytes As [Byte]() = MyUdpClient.Receive(RemoteIpEndPoint) 
    DstPort = RemoteIpEndPoint.Port
    IpRemota(RemoteIpEndPoint.Address.ToString)
    Dim BitDet As BitArray
    BitDet = New BitArray(receiveBytes)
    Dim strReturnData As String = System.Text.Encoding.ASCII.GetString(receiveBytes)
    If UdpOpen Then
        StartUdpReceiveThread(CInt(ListeningPortLbl.Text))
    End If

    PrintLog("From: " & RemoteIpLbl.Text & ":" & ListeningPortLbl.Text & " - " & strReturnData)
    AnswersProcessor(strReturnData)

End Sub

Private Sub UdpSend(ByVal txtMessage As String)
    Dim pRet As Integer
    GLOIP = IPAddress.Parse(RemoteIpLbl.Text)
    'From UDP_Server3_StackOv

    Using UdpSender As New System.Net.Sockets.UdpClient()
        Dim RemoteEndPoint = New System.Net.IPEndPoint(0, My.Settings.UDP_Port)
        UdpSender.ExclusiveAddressUse = False
        UdpSender.Client.SetSocketOption(Net.Sockets.SocketOptionLevel.Socket, Net.Sockets.SocketOptionName.ReuseAddress, True)
        UdpSender.Client.Bind(RemoteEndPoint)
        UdpSender.Connect(GLOIP, DstPort)
        bytCommand = Encoding.ASCII.GetBytes(txtMessage)
        pRet = UdpSender.Send(bytCommand, bytCommand.Length)
    End Using

    PrintLog("No of bytes send " & pRet)
End Sub
Run Code Online (Sandbox Code Playgroud)

Rem*_*eau 2

10013 是WSAEACCES,记录如下

没有权限。

尝试以访问权限禁止的方式访问套接字。一个示例是使用 sendto 的广播地址,而没有使用 setsockopt(SO_BROADCAST) 设置广播权限。

WSAEACCES 错误的另一个可能原因是,当调用绑定函数时(在 Windows NT 4.0 SP4 及更高版本上),另一个应用程序、服务或内核模式驱动程序被绑定到具有独占访问权限的同一地址。这种独占访问是 Windows NT 4.0 SP4 及更高版本的新功能,是通过使用 SO_EXCLUSIVEADDRUSE 选项实现的。