Hey everybody,
I'm just playing around with winsock.
I have made a client that sends a string to the server and then the server sends the string to all the clients including the one that sent it. here is the code.
the problem im having is when i put a break point at the beginning of the for counter the program works... meaning that everybody connected gets the string. now when i take the break point out only the person who sent it gets it. this is the whole code for the server below...
Any help would be appreciated...
thanx
able
I'm just playing around with winsock.
I have made a client that sends a string to the server and then the server sends the string to all the clients including the one that sent it. here is the code.
Code:
Private Sub Socket_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim sItemData As String
Dim strData As String
Dim strOutData As String
' get data from client
Socket(Index).GetData vtdata, vbString
sServerMsg = "Received data from " & Socket(Index).RemoteHostIP & "(" & sRequestID & ")"
List1.AddItem (sServerMsg)
' set data for client
strOutData = vtdata
'send data to client
Dim Counter
For Counter = 1 To lblConnections.Caption
sServerMsg = "Sending data to " & Socket(Counter).RemoteHostIP
List1.AddItem (sServerMsg)
Socket(Counter).SendData strOutData
Next
End Sub
the problem im having is when i put a break point at the beginning of the for counter the program works... meaning that everybody connected gets the string. now when i take the break point out only the person who sent it gets it. this is the whole code for the server below...
Code:
Dim iSockets As Integer
Dim sServerMsg As String
Dim sRequestID As String
Private Sub cmdExit_Click()
End
End Sub
Private Sub Form_Load()
lblHostID.Caption = Socket(0).LocalHostName
lblAddress.Caption = Socket(0).LocalIP
Socket(0).LocalPort = 1007
sServerMsg = "Listening to port: " & Socket(0).LocalPort
List1.AddItem (sServerMsg)
Socket(0).Listen
End Sub
Private Sub socket_close(Index As Integer)
sServerMsg = "Connection closed: " & Socket(Index).RemoteHostIP
List1.AddItem (sServerMsg)
Socket(Index).Close
Unload Socket(Index)
iSockets = iSockets - 1
lblConnections.Caption = iSockets
End Sub
Private Sub Socket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
If Index = 0 Then
sServerMsg = "Connection request id " & requestID & " from " & Socket(Index).RemoteHostIP
List1.AddItem (sServerMsg)
sRequestID = requestID
iSockets = iSockets + 1
lblConnections.Caption = iSockets
Load Socket(iSockets)
Socket(iSockets).LocalPort = 1007
Socket(iSockets).Accept requestID
End If
End Sub
Private Sub Socket_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim sItemData As String
Dim strData As String
Dim strOutData As String
' get data from client
Socket(Index).GetData vtdata, vbString
sServerMsg = "Received data from " & Socket(Index).RemoteHostIP & "(" & sRequestID & ")"
List1.AddItem (sServerMsg)
' set data for client
strOutData = vtdata
'send data to client
Dim Counter
For Counter = 1 To lblConnections.Caption
sServerMsg = "Sending data to " & Socket(Counter).RemoteHostIP
List1.AddItem (sServerMsg)
Socket(Counter).SendData strOutData
Next
End Sub
Any help would be appreciated...
thanx
able