We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


winsock connecting to multiple IP addresses

Medium Priority
Last Modified: 2013-11-13
I am writing a program to control some video projectors that have LAN port connectivity. Each projector will have its own IP address, e.g Projector 1 =, Projector 2 =, etc. They all listen on the same port (I think it is 7142). How do I set up Winsock to send and recieve information from each of the addresses? Do I need multiples instances of Winsock? Please tell me the easiest route, I am fairly new to Winsock functionality.


Keith Frey
Watch Question

Eep.. if you're not well aware of Winsock (I'll take it you mean the control), then you're in for a hassle ahead of you. The connections won't be an issue.. I'm thinking more along the lines of being able to transmit streaming video effectively being the problem.

I'll just try to answer the asked questions.

>> How do I set up Winsock to send and recieve information from each of the addresses? Do I need multiples instances of Winsock?

Multiple instances of winsock for the "control program" would be logical (arrays)...

Private Sub Form_Load()
    Dim iLoop As Integer
    'Add Winsock1 on the form and set it's index property to 0..
    'Loop 2 times..
    For iLoop = 1 To 2
        'Load a new instance of Winsock1.. index=iloop
        Call Load(Winsock1(iLoop))
        'Connect to listening server (i'll ignore index 0)
        Select Case iLoop
            Case 1 'Connect to yahoo for first instance
                Call Winsock1(iLoop).Connect("www.yahoo.com", 80)
            Case 2 'Google for this instance
                Call Winsock1(iLoop).Connect("www.google.com", 80)
        End Select
    Next iLoop
End Sub
Private Sub Winsock1_Connect(Index As Integer)
    Select Case Index
        Case 1
            Debug.Print "Connected to Yahoo! webserver"
            'You can send data like this:
            'Call Winsock1(Index).SendData("your data!")
        Case 2
            Debug.Print "Connected to Google! webserver"
            'Or.. you can close the connection like this:
            'Call Winsock1(Index).Close
    End Select
End Sub

As for the server-side.. I just particpiated in some winsock question based around this:


Basically the same I'd type over so worth a look. All you need to do is specify LocalPort then Listen() and in the ConnectionRequest event procedure, you close the listening socket and Accept() the requestID. After that.. the TCP connection is finalized and the server<->client can begin sending (SendData())/receiving data (DataArrival event procedure)

It's going to be rough implementing it though.. I'm sure others can google and paste some winsock guides/etc. Good luck. :)


Thanks for the quick reply zzzzzooc.

I will try this tomorrow when I am at my desk. As clarification, I am not streaming video, I am sending hex strings to control functions like brightness, contrast, input switching, etc.


Keith Frey

Ah, was thinking there may have been some type of video output from the projectors to the PCs. Basically.. how does the server side function? (IE: If you'll need to start your own listening connection.. If device-drivers/software that interface with the projector already does this and you connect to that.. etc).

I'll reply tomorrow unless this is resolved before then.


Umm, not sure how to answer the question actually. The projector accepts command strings through the LAN port. E.G; "0002010104" + carriage return will turn on the projector. The projector has a port and an IP address. If I set my winsock to the same port but a slightly different suffix in the IP address, I can send commands with no problem.

My issue is that I need to send a command to projector 1 exclusively, and a different command to projector 2. I will be running through a hub to connect to both projectors at the same time. All I need to do is change the IP address I am addressing but I do not understand how to do this.

Oh.. so the LAN has it's own type of server? If it does.. is it listening for UDP or TCP (different procotols)? UDP is basically connection-less and can send/receive "on the go" without verifying the data gets to it's destination. With TCP the connection has to be initiated (meaning the LAN server would have to accept the connection which it may not support). Overall.. it will have to have support of winsock.

Have you read the manual for it? Would be best to get all the facts straight before attempting something and finding out it won't work.


The projector has its own IP address: on port 7142. The protocol is TCP.

Maybe what I did not make clear is that I have succesfully communicated with a projector already with my control program. Although it lacks error trapping, it works for the most part.

What I do not know how to do is to communicate with two projectors that have two IP addresses ( and, they both are on port 7142.

When I tried to close winsock and open it on the new IP address it did not work properly.

If you like, I can send you the program to look at. I am kind of running out of time. I only have tomorrow and Friday to get this working.


Keith Frey


Here is some of my code for now.

Private Sub Form_Load()

        Dim ipStr_1, ipStr_2 As String

                ipStr_1 = ""
                ipStr_2 = ""
        If Winsock1.State = 9 Then
                MsgBox "Warning, port ERROR!"
                Winsock1.Connect ipStr_1
        End If
            txt_Remote_IP_1.Text = ipStr_1
        Projector_Port_1 = Winsock1.RemotePort
            txt_Remote_Port_1 = Projector_Port_1
            txt_Remote_IP_2.Text = ipStr_2
        Projector_Port_2 = Winsock1.RemotePort
            txt_Remote_Port_2 = Projector_Port_2
        txt_Remote_IP_1.FontBold = True
        txt_Remote_IP_2.FontBold = False

End Sub

Private Sub Radio_Select_Projector_1_Click()
        Winsock1.Connect ipStr_1
        txt_Remote_IP_1.FontBold = True
        txt_Remote_IP_2.FontBold = False

End Sub

Private Sub Radio_Select_Projector_2_Click()

        Winsock1.Connect ipStr_2
        txt_Remote_IP_1.FontBold = False
        txt_Remote_IP_2.FontBold = True
End Sub


I pasted your code as shown above in your example and recieved an error:

Message Box

"Compile error"
"Procedure declaration does not match description of event or procedure having the same name"

Can you also explain this line a bit more please? Is 80 the port?
Call Winsock1(iLoop).Connect("www.yahoo.com", 80)

Would I write it for my purposes like this?....
Call Winsock1(iLoop).Connect, 7142)
Unlock this solution and get a sample of our free trial.
(No credit card required)
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.