Re: And here's the answer...
ok now my code looks like this
Option Explicit
Dim Index As Integer
Dim Buffer As String
Private Sub Form_Load()
Index = 0
Sock(Index).Listen
End Sub
Private Sub Sock_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Sock.Accept requestID
Sock(Index).SendData Str(Index)
CommSocket(CommSocket.UBound).Accept requestID
Load sock2(sock2.UBound + 1)
Sock(sock2.UBound).LocalPort = sock2(sock2.UBound - 1).LocalPort + 1
End Sub
Private Sub Sock_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Sock.GetData (Buffer)
If Buffer = Right("/Name:") Then
lstNames.AddItem Right(Buffer, 7)
End If
End Sub
but what winsock control do i use to find out which client index is sending the data????
Going in the wrong direction ....
KnlgHt,
You need to know the basic working of control arrays for using a single winsock control to accept more than one connection.
The MSDN has the necessary code for you, I shall outline what I did in my sample Client-Server program.
Put a winsock control on your form, which will act as the server. Name it tcpServer and it will have the index as 0.
Now remember one thing. You need to put this control i.e. tcpServer(0) in the Listening mode. tcpServer(0) will always stay in the listen mode. Whenever it receives a new connection request, it loads a new winsock into the array and passes on the request to this new winsock control. Remember, tcpServer(0) should never accept the connection request by itself. The connection request must be accepted by another control in the array.
Then you need to have a variable to track the index of the last winsock in the array. Every time you receive a new connection request on tcpServer(0), you increase this variable by 1 and that's the index of the new winsock.