Results 1 to 11 of 11

Thread: Winsock...

  1. #1

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Winsock...

    VB Code:
    1. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    2.     Dim incommingData As String
    3.     Winsock1.GetData incommingData
    4.     Text1 = Replace(incommingData, "\", vbCrLf)
    5. End Sub

    all the data is not coming back.. it seems to get cut off..at 1399

    I know there is more because the last line I see stops mid word...
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  2. #2
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Winsock...

    Do you get another data arrival event with the rest of the data?

  3. #3

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Winsock...

    nope.. I tried making it text1 = text1 & etc...

    I put a msgbox in there.. nothing!???
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Winsock...

    here is all the code: (IP Removed )
    im trying to query a game server (BF2) and the results arent complete
    VB Code:
    1. Private Sub Command1_Click()
    2. Text1 = ""
    3.     Winsock1.SendData Text2
    4.  
    5. End Sub
    6.  
    7. Private Sub Command2_Click()
    8. frmMain.Show
    9. End Sub
    10.  
    11. Private Sub Form_Load()
    12. Winsock1.Connect "xx.xx.xxx.xx", "29900"
    13. End Sub
    14.  
    15. Private Sub Form_Unload(Cancel As Integer)
    16. Winsock1.Close
    17. End Sub
    18.  
    19. Private Sub Text2_KeyPress(KeyAscii As Integer)
    20. If KeyAscii = 13 Then Command1_Click
    21. End Sub
    22.  
    23. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    24.     Dim incommingData As String
    25.     Winsock1.GetData incommingData, vbString, bytesTotal
    26.     Text1 = Text1 & incommingData
    27.     Me.Caption = Len(incommingData) & " : " & bytesTotal
    28. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Winsock...

    anyone?

    do I need to loop somehow in the data arrival to get all of it?
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  6. #6
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Winsock...

    It does this to me too, i have a boolean that is set to true after the first time data arrival come and then the second time it executes my code. However you should be getting a 2nd dataarrival

  7. #7
    Fanatic Member Jumpercables's Avatar
    Join Date
    Jul 2005
    Location
    Colorado
    Posts
    592

    Re: Winsock...

    I wrote a small sender program and the problem I ran into was when you sent the data to the listener program the send was not instantaneous so I had to add a DoEvents to get it to work.

    This might also be the problem when listening for information...Not sure but might be a thought.
    VB Code:
    1. Winsock.SendData (Data)
    2. DoEvents

  8. #8

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Winsock...

    well, when the player list is small.. I get all the data back.. but it seems to cut off after 1399 bytes...
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  9. #9
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Re: Winsock...

    I don't see anything in your code that would be causing the problem. Are you certain that there isn't a problem with the server? Do you know that it sends everything when the player list is large?

    FWIW, here is the Data_Arrival code from one of my apps that receives large records in chunks and appends them until the entire record is received. Other than being a bit more involved, it handles the chunks in the same manner as your code.
    Code:
    Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long)
       ' determine the data type and process it
       
       ' get the buffer contents
       ReDim gbIOBuff(bytesTotal)
       tcpClient.GetData gbIOBuff, vbArray + vbByte, bytesTotal
    
       If copyPtr = 0 Then ' we are at the beginning of a new reply
          ' save size & type of reply
          CopyMemory recLen, gbIOBuff(0), 4     ' get the record length
          recLen = ntohl(recLen)                ' convert to little-endian
          Debug.Print "Record size = " & recLen
          CopyMemory codeCheck, gbIOBuff(52), 2 ' get the reply type
          codeCheck = ntohs(codeCheck)          ' convert to little-endian
          ReDim gbReplyBuff(bytesTotal)         ' clear old data record & start new one
       Else
          ReDim Preserve gbReplyBuff(copyPtr + bytesTotal) ' retain data & bump the size
       End If
       Debug.Print "Bytes received = " & bytesTotal
    
       ' copy the received data to the work buffer at location referenced by copyptr
       CopyMemory gbReplyBuff(copyPtr), gbIOBuff(0), bytesTotal
       If UBound(gbReplyBuff) = recLen Then
          ' we got the entire file
          If codeCheck = glLocRequest Then
             Process_Locations (recLen)       ' called 1 time only at Form_Load
          ElseIf codeCheck = glJobRequest Then
                 Process_JobStats (recLen)     ' called for each chart request
              Else
                 Beep
                 If codeCheck = glError Then
                    CopyMemory ErrIPC, gbIOBuff(0), bytesTotal
                    sbStatus.Panels(2).Text = "Error: " & codeCheck & ", " & _
                                              Left$(ErrIPC.RepErrMsg, ErrIPC.RepMsgLen)
                 Else
                    sbStatus.Panels(2).Text = "Error: " & codeCheck & ", No data returned"
                 End If
                 intTics = 0 ' reset display timer
              End If
          copyPtr = 0   ' reset the flag\pointer
       Else
          ' save the current record length\next copy location
          copyPtr = UBound(gbReplyBuff)
       End If
          
    End Sub
    I added the 2 Debug.Print lines that you see above to demonstrate the chunks arriving for 2 different records. Here is their output:

    Record size = 380
    Bytes received = 380
    Record size = 20378
    Bytes received = 3780
    Bytes received = 3780
    Bytes received = 3780
    Bytes received = 3780
    Bytes received = 3780
    Bytes received = 1478

  10. #10
    Lively Member
    Join Date
    May 2005
    Posts
    90

    Re: Winsock...

    Make sure you aren't receiving byte 0 (or is it 255?) "EOF" chars that cause anything else sent to the textbox to not be shown!
    ^_^

  11. #11
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Winsock...

    Static, a question, why are you using TCP? They send UDP packets

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