Solved

Winsock with VB

Posted on 1998-07-16
3
270 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

808 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