Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winsock Problem

Status
Not open for further replies.

JohnBoy2005

Programmer
Jul 12, 2005
117
GB
I've got a server winsock app that listens for incoming connections from a client app. When a connection is made the IP address of the client is listed in a listbox in the server app.

How can I send data to all of the IP addresses in the list using the same winsock.

Cheers

John
 
You cannot. You have to have a socket for every client you want to send info to. You can load them on the fly as new connections are made, and reuse them as clients disconnect.
-Max
 
I thought I could use one Winsock control in a loop.

For x = 1 to list1.listcount
winsock1.connect IPAddress(x), 1008
Winsock1.SendData txtSend
next x

When I try this, the Winsock1_SendComplete will not trigger to close the Winsock to send the next message in the loop


 
while i have no idea about winsock and everybody is going to hate me for rambeling responses....

I think the problem enlies in ending the connection before starting a new one.

Tom
 
There are a couple things that come to mind.

1. You could create a public variable (lets call it bConnected As Boolean). Then, as soon as you connect, but before sending the data, set bConnected = True. After sending the data you could wait for bConnected = False (which would be done in the SendComplete event).

2. You could create a control array for your winsock component. That way, you wouldn't need to wait for 1 connection to complete before sending the next one.

Of course, these are general ideas, and I have no personal preference for either. Pick a method and try it. If you get stuck, post your code and someone will help you more.

Good luck.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 

You need to wait for each send to complete before opening a new connection.

Code:
'Form Level variable
Private bSending as Boolean

For x = 1 to list1.listcount
   Winsock1.connect IPAddress(x), 1008
   bSending = True
   Winsock1.SendData txtSend
   Do While bSending
      DoEvents
   Loop 
next x

Private Sub Winsock1_SendComplete()
    
    Winsock1.Close
    bSending = false

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top