Solved

Winsock with VB

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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

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…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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.
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.

690 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