Results 1 to 6 of 6

Thread: Receiving data response from foreign server

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Receiving data response from foreign server

    I'm trying to get details from a game server. Basically I would like my application to be able to retrieve ingame statistics without using the game client (to play). Using a sniffer I can see that the packets VB is sending are identical to that which the client sends (so a good start I guess). Connection to the IP/Port also works.

    Now my problem is handling (or getting) received data. I've set the localport to the one the server usually responds with (Winsock1.LocalPort = 2892). Currently I have:
    Code:
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Winsock1.GetData Data, vbString
    Winsock1.LocalPort = 2892
    END SUB
    I'm really interested in learning about this. So my main question is how do I handle any incoming data or how do I know that data is actually being sent back?

    Thanks for any help

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Receiving data response from foreign server

    You don't set the local port of the Winsock control if it's used in a client application. Only for server programs (that accept connections).

    Also, make sure you have Option Explicit at the top of your code. It doesn't look like Data is declared in your data arrival event.

    Try this:

    vb Code:
    1. Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    2.     Dim strData As String
    3.  
    4.     Winsock1.GetData strData, vbString, BytesTotal
    5.     Debug.Print strData
    6. End Sub

    Make sure you press CTRL+G in VB to bring up the debug window so you can see the output.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Receiving data response from foreign server

    Thanks for that. I'm not getting any sense of a responce though, except the fact the connection was successful.

    vb Code:
    1. Private Sub cmdSend_Click()
    2. Winsock1.SendData ".. [email protected]. U..L.e.,.C... .. ........A~...................{"
    3. END SUB

    I assume you can send data in a format like that?

  4. #4
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Receiving data response from foreign server

    When you look at a packet sniffer, dots are usually used in place of other characters that don't display well, ie: Chr$(0).

    Don't look at the text part, look at the hex part, where it has the data as:

    00 32 00 00 00 4D 4F 00
    00 00 00

    etc.

    Those can be represented by: Chr$("&H00") & Chr$("&H32") & Chr$("&H00") etc...

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Receiving data response from foreign server

    Thanks for that. I have a problem, however. When trying to send big packets I'm getting "type mismatch".

    Also is there any easier way to send? Typing Chr$("&H00") is going to take years with the amount of data I need to send

  6. #6
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Receiving data response from foreign server

    What is the line of code that is getting highlighted when you get that error?

    Also, are you able to copy & paste the hex data? You could then use a function like this to generate the all the Chr$() values for the copied hex stuff.

    Just paste the hex data into strHex in this code and run it. Then all the Chr$() values will be in the clipboard and you can just paste them into your code.
    Code:
    Option Explicit
    
    'Accepts a string like: 00 32 00 FD A4 00 etc...
    Private Function GenerateChrs(ByRef HexString As String) As String
        Dim strRet As String, strTemp() As String
        Dim lonLoop As Long
        
        strTemp() = Split(Replace$(HexString, vbCrLf, ""), " ")
        
        For lonLoop = 0 To UBound(strTemp())
            strTemp(lonLoop) = Trim$(strTemp(lonLoop))
            
            If Len(strTemp(lonLoop)) > 0 Then
                strRet = strRet & "Chr$(""&H" & Trim$(strTemp(lonLoop)) & """) & "
            End If
            
        Next lonLoop
        
        If Len(strRet) > 0 And Right$(strRet, 3) = " & " Then strRet = Mid$(strRet, 1, Len(strRet) - 3)
        
        Erase strTemp()
        GenerateChrs = strRet
    End Function
    
    Private Sub Form_Load()
        Dim strHex As String
        
        strHex = "00   32 00 FD A4 00  00 00 00 FD    00 00 00 32"
        
        Clipboard.Clear
        Clipboard.SetText GenerateChrs(strHex)
        
        'Now you're ready to just paste it into your program.
    End Sub

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