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
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:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Winsock1.GetData strData, vbString, BytesTotal
Debug.Print strData
End Sub
Make sure you press CTRL+G in VB to bring up the debug window so you can see the output.
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:
Private Sub cmdSend_Click()
Winsock1.SendData "..
[email protected]. U..L.e.,.C... .. ........A~...................{"
END SUB
I assume you can send data in a format like that?
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...
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 :p
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