Results 1 to 5 of 5

Thread: Winsock API troubles (data send but not recived)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Location
    Slovenia
    Posts
    100

    Winsock API troubles (data send but not recived)

    Hy, im programing online game...
    When client connect to server enything is great, client send data to server and server sends data back but when server sends user data to client, server sings that the data was sent without eny trubles but client doesnt recive enything ---> it even doesnt trigger socket_dataarrial on client and even then when i try to send data to server on server nothing happens...
    Im using TCP protocol and im testing this on localloop back(127.0.0.1)
    and in background is running loop(with doevents) for drawing onscreen and when i close on client server sings error --> Connection closed due to timeout or other faliture(errnum: 10053)
    Can enyone give me idea what can be wrong?
    can be the loop the trouble or is the problem that the data was recived but the event was not triggered?
    Last edited by BlackCatSLO; Jan 15th, 2007 at 05:13 PM.



  2. #2
    Lively Member
    Join Date
    Oct 2006
    Posts
    81

    Re: Winsock API troubles (data send but not recived)

    Hello,
    I didnt understand, you are using Winsock component or API for that?
    And you should show some code, its hard to figure out the problem without seeing the code...
    //jean

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Location
    Slovenia
    Posts
    100

    Re: Winsock API troubles (data send but not recived)

    Sory for my bad english.
    Here is code for my server:
    VB Code:
    1. Private Sub socket_DataArrival(index As Integer, ByVal bytesTotal As Long)
    2. Dim buffer As String
    3. Dim buffer2 As String
    4. Dim sckDataType As Integer
    5. Dim clientinfo As CLIENTINFO_TYPE
    6. Dim serverINFO As SERVERINFO_TYPE
    7. Dim ClientCMD As CMD_TYPE
    8.  
    9.  
    10. With serverINFO
    11.             .clientID = index
    12.             .clientType = 2
    13.             .ConnAllowed = True
    14.             .serverIP = socket(0).LocalIP
    15. End With
    16.  
    17.  
    18.  
    19.  
    20. socket(index).GetData buffer2
    21. ''Debug.Print Len(buffer)
    22.  
    23. buffer = ICStr(buffer2, 0)
    24. sckDataType = ICStr(buffer2, 1)
    25. List1.AddItem sckDataType
    26. List1.AddItem "Getting new info"
    27. If sckDataType = 0 Then
    28.    
    29.     Call CopyMemory(VarPtr(clientinfo), StrPtr(buffer), LenB(clientinfo))
    30.    
    31.     If CleanString(clientinfo.ver) = "0001" Then
    32.  
    33.         buffer = Space(Len(serverINFO))
    34.         Call CopyMemory(StrPtr(buffer), VarPtr(serverINFO), LenB(serverINFO))
    35.        
    36.         socket(index).SendData OGStr(5, buffer)
    37.        
    38.        
    39.    
    40.    
    41.     End If
    42.    
    43.    
    44. ElseIf sckDataType = 10 Then '' if check cmd
    45.    
    46.     Call CopyMemory(VarPtr(ClientCMD), StrPtr(buffer), LenB(ClientCMD))
    47.    
    48.    
    49.    
    50.     If ClientCMD.cmd = 1 And ClientCMD.cmdtype = 0 Then
    51.         Dim usersbuffer As USERME_TYPE: usersbuffer = users(0)
    52.         buffer = Space(Len(usersbuffer))
    53.         '''copy udt to string
    54.         Call CopyMemory(StrPtr(buffer), VarPtr(usersbuffer), LenB(usersbuffer))
    55.         List1.AddItem "Trying to send back user list"
    56.        
    57.         ''''this sends packet to client but client doesnt recive it
    58.         socket(index).SendData OGStr(1, buffer)
    59.        
    60.        
    61.        
    62.         buffer = ""
    63.        
    64.     End If
    65.    
    66.    
    67. Else
    68.  
    69.  
    70. End If
    71.  
    72.  
    73.  
    74. End Sub

    hire is client code

    VB Code:
    1. Private Sub socket_DataArrival(ByVal bytesTotal As Long)
    2.  
    3. Dim SCKdatatype As Integer
    4. Dim ClientCMD As CMD_TYPE
    5.  
    6.     'On Error Resume Next
    7.     strICStr = ""
    8.    
    9.     socket.GetData strICStr, vbString
    10.     If strICStr = "" Then
    11.     socket.PeekData strICStr, vbString
    12.     End If
    13.    
    14.     SCKdatatype = ICStr(strICStr, 1) ''gettype
    15.     strICStr = ICStr(strICStr, 0) ''getout string
    16.     MsgBox "data recived:" & SCKdatatype
    17.        
    18.     qudata = qudata & "-" & bytesTotal
    19.        
    20.     If bolConnecting = True Then
    21.  
    22.        
    23.         If SCKdatatype = 5 Then
    24.             On Error Resume Next
    25.             ''update server info
    26.        
    27.            Call CopyMemory(VarPtr(serverINFO), StrPtr(strICStr), LenB(serverINFO))
    28.                 ClientCMD.cmd = 1
    29.                 ClientCMD.cmdtype = 0
    30.                 buffer = Space(Len(ClientCMD))
    31.                 ''send cmd for recive myplayerinfo
    32.                 Call CopyMemory(StrPtr(buffer), VarPtr(ClientCMD), LenB(ClientCMD))
    33.                 strOutGoing = OGStr(10, buffer)
    34.                 socket.SendData strOutGoing
    35.            
    36.                 bolConnecting = Not serverINFO.ConnAllowed
    37.                
    38.         ElseIf serverINFO.ConnAllowed And SCKdatatype = 1 Then
    39.            
    40.            
    41.                 ''update myplaywer
    42.                
    43.                
    44.                
    45.                 On Error Resume Next
    46.                 Call CopyMemory(VarPtr(MyPlayer), StrPtr(strICStr), LenB(MyPlayer))
    47.                
    48.                
    49.                 bolConnecting = Not serverINFO.ConnAllowed
    50.            
    51.         End If
    52.        
    53.     Else
    54.        
    55.        
    56.         SCKdatatype = ICStr(strICStr, 1) ''data type
    57.         strICStr = ICStr(strICStr, 0) ''get string
    58.         Select Case SCKdatatype
    59.             Case 1
    60.             ''update myplayer
    61.                 On Error Resume Next
    62.                 Call CopyMemory(VarPtr(MyPlayer), StrPtr(strICStr), LenB(MyPlayer))
    63.             Case 2
    64.             ''msg game
    65.                 On Error Resume Next
    66.                 Call CopyMemory(VarPtr(GetMsg), StrPtr(strICStr), LenB(GetMsg))
    67.             Case 3
    68.             ''player info
    69.                
    70.             Case 4
    71.             ''interface cmds
    72.                
    73.             Case 5
    74.             ''server data (only when connecting or changing acctype)
    75.                
    76.             Case 6
    77.             ''adduser
    78.            
    79.             Case 7
    80.             ''remuve user
    81.                
    82.             Case 8
    83.             ''update user
    84.             Case 9
    85.            
    86.            
    87.            
    88.         End Select
    89.    
    90.    
    91.    
    92.     End If
    93.     strICStr = ""
    94.  
    95. End Sub
    96.  
    97.  
    98. Dim utypeClientInfo As CLIENTINFO_TYPE
    99.  
    100. With utypeClientInfo
    101.                 .blowfish = " "
    102.                 .checksum = "test"
    103.                 .ver = "0001"
    104.  
    105. End With
    106. strOutGoing = Space(LenB(utypeClientInfo))
    107. Call CopyMemory(StrPtr(strOutGoing), VarPtr(utypeClientInfo), LenB(utypeClientInfo))
    108.  
    109. sending = True
    110. bolConnecting = True
    111. socket.SendData OGStr(0, strOutGoing)
    112. strOutGoing = ""
    When is clicked button for start starts drawing loop and connect to server that loop is looping utill the client dont recives all myplayer data

    Edit: Im using winsock component i dont know but i think this is problem
    Last edited by BlackCatSLO; Jan 16th, 2007 at 04:40 PM.



  4. #4
    Lively Member
    Join Date
    Oct 2006
    Posts
    81

    Re: Winsock API troubles (data send but not recived)

    i really dont think there is a problem with winsock or sending data, i think the problem could be dealing the strings.. i dont know functions you use to handle the strings, but maybe they dont return the right string, but nullstring, and in the result you send/recieve nullstring..

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Location
    Slovenia
    Posts
    100

    Re: Winsock API troubles (data send but not recived)

    sory i forget to said that the OGStr and ICStr are my functions but they are just for testing
    i have to rewrite this functions becouse they were primary for other project
    VB Code:
    1. Public Function OGStr(tip As Integer, ByVal str As String) As String
    2. Dim tipe As String
    3.  
    4.  
    5. Select Case tip
    6.     Case 0
    7.     ''client presentation
    8.         tipe = "G000"
    9.     Case 1
    10.     ''client clientid
    11.         tipe = "G001"
    12.     Case 2
    13.     ''msg game
    14.         tipe = "G002"
    15.     Case 3
    16.     ''player info
    17.         tipe = "G003"
    18.     Case 4
    19.     ''interface cmds
    20.         tipe = "G004"
    21.     Case 5
    22.     ''server presentation
    23.         tipe = "G005"
    24.     Case 6
    25.     ''adduser
    26.         tipe = "G006"
    27.     Case 7
    28.     ''removeuser
    29.         tipe = "G007"
    30.     Case 8
    31.     ''update user
    32.         tipe = "G008"
    33.     Case 9
    34.     ''moving to...
    35.         tipe = "G009"
    36.     Case 10
    37.     ''client or server cmd
    38.         tipe = "G010"
    39.     Case Else
    40.     ''eror
    41.         tipe = "Err"
    42. End Select
    43. If tipe <> "Err" Then
    44.     OGStr = Chr(1) & tipe & str & Chr(23)
    45. End If
    46. End Function
    47. Public Function ICStr(ByVal str As String, ByVal TyorStr As Byte) As String
    48. Dim tip As String
    49. Dim tipe As Integer
    50.  
    51. ''str = Left(str, Len(str) - 1)
    52. ''str = Right(str, Len(str) - 1)
    53. str = str
    54. tip = Left(str, 4)
    55. str = Right(str, Len(str) - 4)
    56.  
    57. If TyorStr = 1 Then
    58.     Select Case tip
    59.         Case "G000"
    60.         ''client presentation
    61.             tipe = 0
    62.         Case "G001"
    63.         ''client clientid
    64.             tipe = 1
    65.         Case "G002"
    66.         ''msg game
    67.             tipe = 2
    68.         Case "G003"
    69.         ''player info
    70.             tipe = 3
    71.         Case "G004"
    72.         ''interface cmds
    73.             tipe = 4
    74.         Case "G005"
    75.         ''server data (only when connecting or changing acctype)
    76.             tipe = 5
    77.         Case "G006"
    78.         ''adduser
    79.             tipe = 6
    80.         Case "G007"
    81.         ''remuve user
    82.             tipe = 7
    83.         Case "G008"
    84.         ''update user
    85.             tipe = 8
    86.         Case "G009"
    87.         ''moving to...
    88.             tipe = 9
    89.         Case "G010"
    90.         ''client or server cmd
    91.             tipe = 10
    92.            
    93.         Case Else
    94.         ''eror
    95.             tipe = -1
    96.     End Select
    97.     ICStr = tipe
    98. ElseIf TyorStr = 0 Then
    99.     ICStr = str
    100.  
    101. End If
    102. End Function

    I dont think my winsock sends null string becouse i save every string in file for debuging and there are all strings.
    When i read them with other program they are fine with all data and they can be copy in to UDT with no missing data or errors :/



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width