PC Review Forums Newsgroups Microsoft DotNet Microsoft Dot NET Framework Problem with UDP socket under NET Framework

Reply

Problem with UDP socket under NET Framework

 
Thread Tools Rate Thread
Old 08-07-2003, 08:39 AM   #1
Volodia
Guest
 
Posts: n/a
Default Problem with UDP socket under NET Framework


I have a problem with using UPD under NET framwork.
The problem consist if any client disconnect under UDP protocol
from server ( code below ) it raise exeption 10054 -
It shouldn't be under UDP protocol - becouse this protocol is
connectionless and does not have any notification about closing.

Exeption 10054 is:
An existing connection was forcibly closed by the remote host.

Thanks,
Volodia.


UDP server code (by the way - client done in unmanaged C++) :

Sub ThreadProc()

_ReceivingSocket = New Socket(AddressFamily.InterNetwork, _
SocketType.Dgram, ProtocolType.Udp)

_ReceivingSocket.SetSocketOption(SocketOptionLevel.Socket, _
SocketOptionName.ReuseAddress, 1)

Dim listenEndPoint As IPEndPoint = New IPEndPoint(IPAddress.Any, _Port)
_ReceivingSocket.Bind(listenEndPoint)

Dim state As New StateObject
Dim nodecallback As New AsyncCallback(AddressOf RecieveCallback)

Dim nodeIP As IPEndPoint = New IPEndPoint(IPAddress.Any, 0)
Dim nodeEP As EndPoint = DirectCast(nodeIP, EndPoint)

While NodeListenerRun > 0

ReadDone.Reset()

Try

_ReceivingSocket.BeginReceiveFrom(state.buffer, 0, _
state.BufferSize, SocketFlags.None, nodeEP,
nodecallback, state)

ReadDone.WaitOne()

Catch sex As SocketException

If (sex.ErrorCode = 10040) Then
state.IncreaseBuffer()
Else
SwitchSocketOff()
End If

Catch exp As Exception

CloseListening()

End Try

End While

End sub


Private Shared Sub RecieveCallback(ByVal ar As IAsyncResult)

Try
'
' Get state object
'
Dim state As StateObject = CType(ar.AsyncState, StateObject)

'
' Creates a temporary EndPoint to pass to EndReceiveFrom.
'
Dim sender As New IPEndPoint(IPAddress.Any, 0)
Dim fromEP As EndPoint = CType(sender, EndPoint)

'
' Get number of bytes.
'
Dim bytesRead As Integer = state.workSocket.EndReceiveFrom(ar,
fromEP)
Dim str As String

If bytesRead > 0 Then

str = Encoding.ASCII.GetChars(state.buffer, 0, bytesRead)

'
' Process data
'
ClientResponce(state, fromEP, str)

End If

Catch sex As SocketException

If (sex.ErrorCode = 10054) Then

SwitchSocketOff()
Tracing("Listener RecieveCallback : " & sex.Message)

End If

Catch ex As Exception

Tracing("Listener RecieveCallback error: " & ex.ToString)

End Try

'
' All data was get, so reset event.
'
ReadDone.Set()

End Sub


  Reply With Quote
Old 08-07-2003, 05:54 PM   #2
Alan J. McFarlane
Guest
 
Posts: n/a
Default Re: Problem with UDP socket under NET Framework

Volodia <GroundSoft@hotmail.com> wrote:
> I have a problem with using UPD under NET framwork.
> The problem consist if any client disconnect under UDP protocol
> from server ( code below ) it raise exeption 10054 -

[...]
See http://support.microsoft.com/?kbid=263823 "263823 - WinSock Recvfrom()
Now Returns WSAECONNRESET Instead of Blocking or Timing Out".
--
Alan J. McFarlane
http://homepage.ntlworld.com/alanjmcf/
Please follow-up in the newsgroup for the benefit of all.


  Reply With Quote
Old 09-07-2003, 06:37 AM   #3
Volodia
Guest
 
Posts: n/a
Default Re: Problem with UDP socket under NET Framework

Thanks.

"Alan J. McFarlane" <alanjmcf@yahoo.com> wrote in message
news:sVCOa.5230$ju6.94457@newsfep4-glfd.server.ntli.net...
> Volodia <GroundSoft@hotmail.com> wrote:
> > I have a problem with using UPD under NET framwork.
> > The problem consist if any client disconnect under UDP protocol
> > from server ( code below ) it raise exeption 10054 -

> [...]
> See http://support.microsoft.com/?kbid=263823 "263823 - WinSock Recvfrom()
> Now Returns WSAECONNRESET Instead of Blocking or Timing Out".
> --
> Alan J. McFarlane
> http://homepage.ntlworld.com/alanjmcf/
> Please follow-up in the newsgroup for the benefit of all.
>
>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off