An already running application now receives socket error 10013

I have an application running in VB.NET that listens on a specific UDP port and responds through the same port to the IP address that sends the packet. It worked fine from two years until the last month; now that you are trying to respond to a failure due to socket error 10013.

I even try to use an older version, and I know that it works too and gets the same crash.

I am trying to disable real-time protection of Microsoft Security Essentials and the Windows Firewall and it is not working.

In the code, I have a line

MyUdpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, True) 

I have no idea what to do, I'm lost.

Any idea how to solve this?

Edit: Here is the code

 #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 
+6
source share
2 answers

10013 WSAEACCES , which is documented as follows:

Permission denied.

An attempt was made to access a socket that was denied by its access permissions. An example is the use of the broadcast address for sendto without the broadcast permission specified with setsockopt (SO_BROADCAST).

Another possible cause of the WSAEACCES error is that when the bind function (in Windows NT 4.0 Service Pack 4 and later) is called, another application, service, or kernel mode driver is bound to the same address with exclusive access. This exclusive access is a new feature of Windows NT 4.0 Service Pack 4 and later and is implemented using the SO_EXCLUSIVEADDRUSE option.

+2
source

In the comments you mentioned:

I tried the program on XP x32 and it works fine, but on Windows 7 x32 / x64 it doesnโ€™t, even if I disable the firewall and Microsoft Security Essentials Live Protection.

This may sound pretty obvious, but you can try running your program in all available Windows XP compatibility modes. You did not say that you have already tried this, but maybe you are lucky and the problem will be solved by this workaround.

If the problem still exists and given error code 10013, I would try to check the following things:

  • I know that you have disabled Microsoft Security Essentials and the Windows Firewall, but double-check if there are other security-related programs and services, such as antivirus protection, antivirus programs, etc. Something seems to be blocking socket creation / binding.
  • In case your program generated output / log data that allows you to see exactly when it started to crash:
    • Any new software installed at that time?
    • Were Windows updates (possibly automatically) installed at this time? Especially security updates regarding network security?
    • Any other noticeable changes in your environment? What about log entries in windows syslog?

  • As a small test to check if an error occurs only with your UDP socket: try using a TCP socket instead of UDP.

  • Start the device in safe mode Windows with network support and run your program from there.

  • Run the program on another computer running Windows 7 and check if the same problem occurs there. This can be a valuable starting point (in terms of localization) to find out if the problem only occurs in certain versions of Windows.

  • One step through your code with a debugger and carefully monitor what happens. Perhaps this may show additional information about what is going wrong.

Perhaps some of the ideas above will help you sort out the problem a bit. Good luck

+1
source

All Articles