VB6 - Winsock, Auto find server using UDP Broadcast (LAN ONLY)
I attached a Client and a Server program, a simple Chat program demonstrating how to connect to the server without knowing the server's IP.
This is done by broadcasting a message from the client to the entire network, when server receives the message, server will broadcast another message giving it's IP and port number to use to connect to it. When client receives the server's message, it knows where to connect to using TCP connection.
Here's Pseudo code on what's going on (the messages that are sent back and forth)
Client broadcasts: "Where are you ?" (Could be anything, this is just an example)
Server receives message
Server broadcasts: "IP=192.128.0.1, Port=8888" (the IP and port # are just examples)
Client receives server's message, and knows where to connect to
Client connects to server using TCP
Re: VB6 - Winsock, Auto find server using UDP Broadcast (LAN ONLY)
hi
thanks for your implementation really good.
i do i connect to a server(vb winsock) from outside the lan. that is if my server is located in my computer in my work place which is behind a router or which is in a lan network . is there any way to connect to this server from my home intrernet enabled computer
Re: VB6 - Winsock, Auto find server using UDP Broadcast (LAN ONLY)
CVMichael...
I'm trying to develop your application about winsock send file.
if Server Runn, it will send his IP to Client, so when client need to send a File he just choose an IP of the server that he want to send. without type the IP
when any another 2 PC running U'r winsock sever application. All winsock server
send(Broadcast) their IP addres to PC whose Running Winsock Client(Bind).
I found a code Like This:
' server side
Private Sub Command1_Click()
On Error Resume Next
For x = 420 To 440
Winsock1.Close
Winsock1.RemoteHost = "255.255.255.255"
Winsock1.RemotePort = x
Winsock1.SendData winsock1.LocalIp
Next
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Winsock1.Close
Me.Caption = "BoardCast Server"
End Sub
Private Sub Timer1_Timer()
Command1_Click
End Sub
' Client Side
Dim IP As Integer
Private Sub Form_Load()
Me.Caption = "BoardCast Client"
IP = 420
On Error GoTo errIP
Winsock1.Bind IP
Exit Sub
errIP:
IPIncrease
Exit Sub
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
On Error GoTo errIP
Dim strData As String
Winsock1.GetData strData
Text1.Text = strData ' <-----------Here My problem, listen only 1 IP if any another aplication winsock server run, his IP showed too at here(text1.text)
Exit Sub
errIP:
IPIncrease
End Sub
Sub IPIncrease()
On Error GoTo errIP
IP = IP + 1
Winsock1.Close
Winsock1.Bind IP
Exit Sub
errIP:
IPIncrease
End Sub
Last edited by Aan2702; May 18th, 2008 at 01:11 PM.
Re: VB6 - Winsock, Auto find server using UDP Broadcast (LAN ONLY)
CMichael..
I've been use your application Send File using winsock, to send via internet.
and I've been set my router DNS to No-IP here's mine http://aan.redirectme.net
I run the server application and Client application at the same PC.
and From Client side I type Remote host = aan.redirectme.net, with remote port = 80. And it's work but not 100% compleate.
Re: VB6 - Winsock, Auto find server using UDP Broadcast (LAN ONLY)
Regarding running multiple servers.... well... you are not supposed to... you are supposed to run only one server, and multiple clients.
But if you want to fix the problem, simply don't accept any new connections if you are already connected.
About the file transfer program, it works fine on my computer, so there is nothing I can do here to fix your problem. You should debug & find where the problem occurs by yourself, then try to fix it...
And about no-ip.com, I've been using it for a few years, and I did not pay at all.... of course they offer the option that if you pay you get more features, but if you just want a DNS name, then you don't have to pay... Right on the main page it says "No-IP Free"
Re: VB6 - Winsock, Auto find server using UDP Broadcast (LAN ONLY)
Thank's For Replay My question CVMichael..
I'm still confused to using No-IP.
or maybe I'm wrong because..on my NO-IP account, I add a host called aan.redirectme.net (I'm direct incoming packet from my external IP on port 80 into my PC with port 8686)
I hope when You have a free time , you can showed me little experiment about Your aplication. send data through internet. I'll became a server and you can send me a data. from aan.redirectme.net. Thanks' anyway
Re: VB6 - Winsock, Auto find server using UDP Broadcast (LAN ONLY)
CVMicheal if am writing a stand alone app (chat app) must i use a public host to portforward brfore i can connect to another computer in another network lan?