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

Tech-Archive recommends: Speed Up your PC by fixing your registry



You can, you just need to make sure the client is binding to a different
port then the server, (In case they are both running on the same machine).
I threw this together, and it worked first try, so I suppose it should work
for what you want. I tried it on 2 machines, and I got the remote IP from
both of them:
(Just a form, 2 winsocks, a textbox -multiline-, and a command button)

Option Explicit

Private Sub Command1_Click()
Winsock2.Close
Winsock2.Protocol = sckUDPProtocol
Winsock2.LocalPort = 5555
Winsock2.RemotePort = 5556
Winsock2.Bind

Winsock1.Close
Winsock1.Protocol = sckUDPProtocol
Winsock1.LocalPort = 5556
Winsock1.RemoteHost = "255.255.255.255"
Winsock1.RemotePort = 5555
Winsock1.Bind

Winsock1.SendData "IP O'Negai Shimasu"

End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim sData As String

Winsock1.GetData sData, vbString, bytesTotal
Text1.Text = sData & vbCrLf & Text1.Text
End Sub

Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Dim sData As String
Winsock2.GetData sData, vbString, bytesTotal
If sData = "IP O'Negai Shimasu" Then
Debug.Print "Ip Request detected from IP " & Winsock2.RemoteHostIP
Winsock2.SendData Winsock2.LocalIP
End If
End Sub





"Gilles Ganault" <nospam@xxxxxxxxxx> wrote in message
news:0ui59397p79q1g7tcvdk3q8od5n7mj4aip@xxxxxxxxxx
On Mon, 9 Jul 2007 14:27:47 -0600, "Lance Wynn"
<LanceWynn@xxxxxxxxxxxxxxxx> wrote:
Since UDP is connectionless, you basically have to follow this process
flow
(or something like it):

Thanks for the algo.

What I don't understand, is... if I really have to open a UDP socket
on the client for the server to reply to the broadcast (instead of
having the server reuse the socket that the client used to broadcast
the message), why does it work the first time?


.


Quantcast