# VBForums CodeBank > CodeBank - Visual Basic 6 and earlier >  VB6 - Winsock, Auto find server using UDP Broadcast (LAN ONLY)

## CVMichael

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

----------


## coolcurrent4u

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

----------


## CVMichael

Using this method you cannot go outside the local network because the router will not pass UDP broadcasts...

You need a DNS name for your home computer, then you can connect to it from anywhere...

----------


## Aan2702

Hi. Im interested to use winsock send file via internet. behind router
how can I setting up dns for my computer..

----------


## CVMichael

Hi Aan2702, welcome to the forums  :wave:  

I personally use this one: http://www.no-ip.com/ , it's free...

----------


## Aan2702

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)  :Ehh:  

    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

----------


## Aan2702

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.

 here my print Screen http://img218.imageshack.us/my.php?i...7125407rc7.jpg

Please help what's the problem..about this CMichael.

ehmm..maybe we have to paid on http://www.no-ip.com/

----------


## CVMichael

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*"

----------


## Aan2702

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

----------


## coolcurrent4u

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?

----------


## lhx3lsoft

Aan2702,CVMichael
can you help me

----------


## supersimha

Hi I just want to ftp a file from my windows to linux machine. The linux machine ip is known. Its in the local area network. Please help

----------


## coolcurrent4u

There is a bug in the implementation, if you try to connect more that one client, i get a "address in use" error?

have any of you manage to resolve this

----------


## flyhigh

this lan means everything on say a home or office network?
and the adminstrater  gets  the client or the server?

----------


## morkie

how can i display the list of connection in listbox...
the list of servers they want to connect with them...

----------

