Advertisement

vb winsock problem

Started by March 18, 2003 06:15 PM
-1 comments, last by DarkNebula 21 years, 10 months ago
got a problem with sending corrds though winsock, i get a mixture of the strings from the other clients that send data here is my code:


Private Sub wsClient_DataArrival(ByVal bytesTotal As Long)
 Dim sckDataRecived As String, Cmd As String
 
    sckDataRecived = ""
    wsClient.GetData sckDataRecived
    
    If sckDataRecived = "dat" Then
        wsClient.SendData "(usn)" & frmConnect.txtUser.Text
        Exit Sub
    End If
    
    With Cameras.Camera_GetPosition
        cX = .x
        cY = .y
        cZ = .z
              
    End With
    
    
    Dim CurrPos
    
    Cmd = Trim$(Mid$(sckDataRecived, 2, 3))
    
      
    Select Case Cmd
        
        Case "usn"
        
            UserName = Trim$(Mid$(sckDataRecived, 6, Len(sckDataRecived)))
            lstUsers.AddItem UserName
            sckDataRecived = ""
            
            
        Case "XXX"
        
            TTick = CInt(Len(sckDataRecived))
            TTick = TTick - 5
            CurrPos = Trim$(Mid$(sckDataRecived, 6, TTick))
            MeshBuilder2.Class_SetPointer "person"
            MeshBuilder2.Mesh_SetPosition Helper.R3DVector3D(CurrPos, cY, cZ)
            sckDataRecived = ""
            
        Case "YYY"
        
            TTick = CInt(Len(sckDataRecived))
            TTick = TTick - 5
            CurrPos = Trim$(Mid$(sckDataRecived, 6, TTick))
            MeshBuilder2.Class_SetPointer "person"
            MeshBuilder2.Mesh_SetPosition Helper.R3DVector3D(cX, CurrPos, cZ)
            sckDataRecived = ""
            
        Case "ZZZ"
        
            TTick = CInt(Len(sckDataRecived))
            TTick = TTick - 5
            CurrPos = Trim$(Mid$(sckDataRecived, 6, TTick))
            MeshBuilder2.Class_SetPointer "person"
            MeshBuilder2.Mesh_SetPosition Helper.R3DVector3D(cX, cY, CurrPos)
            sckDataRecived = ""
              
     End Select

End Sub

 
Client


Private Sub wsServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)

SocketCount = SocketCount + 1

Load wsServer(SocketCount)
wsServer(SocketCount).Accept requestID

wsServer(SocketCount).SendData "dat"



End Sub


Private Sub wsServer_DataArrival(Index As Integer, ByVal bytesTotal As Long)

Dim strRecivedData As String
Dim SocketCheck As Integer
Dim FixPre As String
Dim UserName As String
Dim tttick As Single

strRecivedData = ""
wsServer(Index).GetData strRecivedData
DoEvents

FixPre = Trim$(Mid$(strRecivedData, 2, 3))

Select Case FixPre
    
    Case "usn"
        UserName = Trim$(Mid$(strRecivedData, 6, Len(strRecivedData)))
        lstUsers.AddItem UserName
        For SocketCheck = 0 To SocketCount Step 1
         
         
        If wsServer(SocketCheck).State = sckConnected Then
                wsServer(SocketCheck).SendData strRecivedData
                DoEvents
                
                
        End If
Next SocketCheck
strRecivedData = ""
Exit Sub
                
    End Select
    

 
For SocketCheck = 0 To SocketCount Step 1
         
         
        If wsServer(SocketCheck).State = sckConnected Then
                wsServer(SocketCheck).SendData strRecivedData
                DoEvents
                
        End If
Next SocketCheck
strRecivedData = ""

End Sub

 
DarkNebula

This topic is closed to new replies.

Advertisement