Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Winsock Visual Basic Question

Posted on 2014-04-13
5
Medium Priority
?
1,211 Views
Last Modified: 2014-04-13
I have a Visual Basic 6 application that I'm writing to connect to two remote micro-controllers.  The micro controllers each have their own IP addresses and ports.  My laptop application has two Winsock controls in a form that I connect and try to read/write data to each controller.  Both controllers are Arduino Ethernets and are programmed to be servers.  My application on my laptop is programmed to connect to each using "sckTCPProtocol".  

Controller 1: Winsock1      192.168.1.100         port 11010
Controller 2: Winsock2      192.168.1.101         port 11011

In my Visual Basic application, I make the connections on loading the app, then I have a timer that I placed the winsock.sendData command in such that I intend to "sendData" periodically to Winsock1 and Winsock2.  Unfortunately, I can't seem to send data to both at the same time.  Both connect but I can't send data to both when running in the same application.  I can comment one and send to the other and vice versa.  But I can't send data to both in the application.  I've tried closing one connection and alternating but that doesn't work.  I don't want to run two separate executables.  

Private Sub Timer1_Timer()
        If Not Winsock2.State = sckConnected Then
                'Winsock2.Connect
                 Winsock2.SendData Packet2
                 'Winsock2.Close
        End If

       
        If Not Winsock1.State = sckConnected Then
                'Winsock1.Connect
                Winsock1.SendData Packet1
                'Winsock1.Close
        End If
End Sub

Any suggestions?  Definitely need help on this one.
0
Comment
Question by:ScottVeitch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 35

Accepted Solution

by:
Bembi earned 1500 total points
ID: 39997474
Have you tried to close the first connection, then put a DoEvents there and then open the second one to send data. DoEvents allows the system to process background task.
0
 
LVL 25

Expert Comment

by:chaau
ID: 39998085
To connect to more than one host you need to create a Winsock array. You do this by setting a different index for each of the controls. Set the Index property of Winsock1 to 0, and Winsock2 to 1, like this:
Winsock1.Index = 0
Winsock2.Index = 1

Open in new window

You can do this in designer, I believe.
0
 
LVL 12

Expert Comment

by:jkaios
ID: 39998165
0
 
LVL 12

Expert Comment

by:jkaios
ID: 39998167
...Or these...

Creating Client/Server Application using Winsock:
   http://www.codeproject.com/Purgatory/winsock.asp

Using the Winsock Control in Client/Server Applications:
   http://www.15seconds.com/issue/010820.htm

Winsock Programming:
   http://www.devx.com/vb2themax/Article/19879/1954?pf=true
0
 

Author Closing Comment

by:ScottVeitch
ID: 39998190
Using the DoEvents definitely worked.  However, I didn't need to close or open any connections.  I just had the DoEvents in the Sub( ) after the first Winsock1.sendData prior to the second Winsock2.sendData.  Works like a champ now.  Thank you very much.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question