Solved

Winsock with VB

Posted on 1998-07-16
3
266 Views
Last Modified: 2013-11-13
After creating an array of winsock controls for multi-connection.accepts, I want to do a simple For Each loop to send a string of data.
For Each Player1 In colCurrentPlayers

   tcpChessServer(Player1.intPlayerIndex).SendData strAllPlayers

Next Player1
The problem is if I have multiple connections going when this code runs it sends the data inconsistently. One instance will read it right and another two may have missed it all together. Do I need to wait until each .SendData is complete before the loop continues???
Any VB source code dealing with Winsock would be greatly appreciated.
Thanks,
Kyle
0
Comment
Question by:kylemann
3 Comments
 

Author Comment

by:kylemann
ID: 1466018
Edited text of question
0
 
LVL 1

Expert Comment

by:brunchey
ID: 1466019
Yes, basically what you are doing here is asynchronous activities, meaning once you tell the winsock control to do something it does it, not waiting for anything else that you may want to do.  So yes, you need to wait until the .SendData method has completed to send the next one to make sure that it occurs.  I am sorry that I don't have any code for this as I have not used the winsock control for a while, but maybe there is an event in the control that you can run a loop statement that waits for some boolean variable to be changed in that event.
0
 
LVL 6

Accepted Solution

by:
anthonyc earned 100 total points
ID: 1466020
Kyle,

Use DOEVENTS after each send, and it should work.  

Also, if you want to loop through a bunch of winsocks you can do this

dim x as winsock

for each x in winsock1()
   x.senddata "hi"
next x
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now