Re: [Winsock UDP] Why .Close to avoid Err 40020?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Fri, 6 Jul 2007 15:52:21 -0600, "Lance Wynn"
<LanceWynn@xxxxxxxxxxxxxxxx> wrote:
You cannot set the Protocol after the connection is open (Which in the case
of UDP probably happens when you send your first data).

Thanks guys. It helped :-)

The next step, is having...
1 the server wait on UDP 5555
2. the client broadcast a string on UDP 5555 with remote IP
255.255.255.255 asking for the server's IP
3. the server answer this with its local IP

The goal is obviously to locate a server without having to set its IP
address on each client. I'll figure out later how to handle the case
where the server can't use the default UDP port because it's already
in use.

With the following code, it works the first time, but if I click on
the client's Command1 or even close/restart the client, the server
does receive the broadcast but doesn't send its IP address:

====== SERVER ============
Option Explicit

Private Sub Form_Load()
ServerSock.Protocol = sckUDPProtocol
ServerSock.LocalPort = 5555
ServerSock.Bind
End Sub

Private Sub ServerSock_DataArrival(ByVal bytesTotal As Long)
Dim strDataIn As String

ServerSock.GetData strDataIn

Label1.Caption = strDataIn + vbCrLf + ServerSock.RemoteHostIP +
vbCrLf + _
Str(ServerSock.RemotePort) + vbCrLf + Time$

'After first, successful transmission, server stops TXing!
ServerSock.SendData ServerSock.LocalIP

'Required, or server will not answer subsequent requests with
'Err 10054 "The connection is reset by remote side"
ServerSock.Close

'Makes no difference
'ServerSock.Protocol = sckUDPProtocol
'ServerSock.LocalPort = 5555

ServerSock.Bind
End Sub

====== CLIENT ============
Option Explicit

Private Sub ClientSock_DataArrival(ByVal bytesTotal As Long)
Dim sStuff As String

ClientSock.GetData sStuff

'Needed? DoEvents

Label1.Caption = "Remote address " & sStuff & vbCrLf & Time$
End Sub

Private Sub Command1_Click()
'Required to avoid error 40020: "Invalid operation at current
state"
If ClientSock.State <> sckClosed Then
ClientSock.Close
End If

ClientSock.Protocol = sckUDPProtocol
ClientSock.RemotePort = 5555
ClientSock.RemoteHost = "255.255.255.255"

ClientSock.SendData "SERVER_IP_ADDRESS_PLEASE"

End Sub

Private Sub Form_Load()
ClientSock.Close
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
ClientSock.Close
End Sub
====== END ============

Does the server need to be reset with something else besides what I
commented out because it made no difference?

I remember there was a lot of useful infos on www.vbip.com, but the
site is gone and his author Oleg Gdalevich's whois e-mail doesn't work
:-(

Thanks for any help.
.



Relevant Pages

  • Re: What is the minimum-size UDP packet?
    ... > with the server but for scalability reasons there is not a one to one map ... A client may disconnect ... If the server hasn't received a valid session ID via UDP from the ... Connectionless - there is no connection. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: What is the minimum-size UDP packet?
    ... > with the server but for scalability reasons there is not a one to one map ... A client may disconnect ... If the server hasn't received a valid session ID via UDP from the ... Connectionless - there is no connection. ...
    (microsoft.public.win2000.networking)
  • My goal is a _really slow_ connection
    ... We try to transfer a small file from server 172.16.3.1 via ... How do I keep the server from repeating too ... Is there an option / a command to make the IP level on the client ... udp 191 ...
    (alt.os.linux.suse)
  • My goal is a _really slow_ connection
    ... We try to transfer a small file from server 172.16.3.1 via ... How do I keep the server from repeating too ... Is there an option / a command to make the IP level on the client ... udp 191 ...
    (comp.os.linux.development.system)
  • Re: Problem with certificates/L2TP VPN
    ... Do you have Kerberos (port 88 on UDP & TCP) open? ... of RRAS server. ... The client IS behind NAT. ... UDP 500 - for IKE ...
    (microsoft.public.windows.server.networking)