Solved

Deciphering byte stream returned from server

Posted on 2000-05-01
11
230 Views
Last Modified: 2008-03-17
I writing a VB application that:

(1) queries a game master server to receive a list of
IP addresses and Port numbers of servers running a
particular game.  

(2) query the individual game servers and return information
such as ping, current map, max number of players and actual
number of players on the server.

I have #2 down (assuming I feed it known IPs and Port numbers.)

I'm having trouble with #1

The documentation for this process is pretty thin:

"... server returns the following:
 -1 (a four byte integer, i.e. FF, FF, FF, FF)
 'f' (single ASCII char)
 '\r' (ASCII carriage return)

 Unique_ID (4 byte unique ID number)

 IP address (4 bytes, highest octect first)
 Port number (2 byte integer, big endian format)"


Here is a breakdown of the first 16 bytes that my app.
received from the master server:


Cloumn |Byte      |Ascii/
No.       |Received|Chr$
-----------------------
 1         |ÿ            |255
 2         |ÿ            |255
 3         |ÿ            |255
 4         |ÿ            |255
 5         |f             |102
 6         |vbCr       |13
 7         |p            |112
 8         |t             |116
 9         |           |2
10        |              |0
11        |Ï             |207
12        |¾           |190
13        |           |18
14        |6            |54
15        |i             |105
16        |‡            |135

This is what I know:

Bytes 1 - 4 are four consecutive bytes of '\0' in C/C++ or
chr$(255) in VB - the 32-bit integer -1

Byte 5 is the ascii character 'f'

Byte 6 is the ascii carriage return character '\r' in C/C++ or
chr$(13) in VB

Bytes 7 - 9 are the Unique ID number for each batch of IPs and
Ports from the Master Server (4 bytes)

Bytes 11-14 are the IP address (4 bytes - highest octect first)

Bytes 15&16 are the Port (a 16-bit integer) for the preceding IP
(2 bytes - big endian format: the "big end" of the 2 byte word is sent
first)

What I don't know is how to convert the bytes for IP and Port correctly.

Another quote:
"With Bytes 15 and 16 (the port number in big endian format) the port
number is 27015 (0x69, 0x87 hex). It is sent as chr$(105), then chr$(135),
not as chr$(135) then chr$(105) (like a NORMAL Intel integer)."

QUESTION#1=> How do you translate four consecutive bytes of chr$(255) to -1?

QUESTION#2=> What would the IP address be of chr$(207), chr$(190), chr$(18), chr$(54)?

QUESTION#2=> How do you get 27015 out of chr$(105) and chr$(135)?
I know that hex(105) = 69 and hex(135) = 87. How do you arrive at 27015?

Thanks!
Greg
0
Comment
Question by:mtosh
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 32

Accepted Solution

by:
bhess1 earned 150 total points
ID: 2766699
The IP address in text format from the byte stream would be something like this (assuming that one server's info is in a byte array 1-16)

Dim SrvrInfo(1 to 16) as Byte
Dim IPAddr as String
Dim Port as Integer

Get_Server_Info   ' Load array with byte stream

IPAddr = SrvrInfo(11) & "." & SrvrInfo(12) & "." & SrvrInfo(13) & "." & SrvrInfo(14)

Port = SrvrInfo(15) * 256 + SrvrInfo(16)

0
 
LVL 38

Expert Comment

by:PaulHews
ID: 2766785
Here's some sample code to convert bytes to a signed long and to a signed integer.  There is a note on how to convert to an unsigned integer below in a comment.

Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, _
    Source As Any, ByVal Length As Long)

Private Sub Command1_Click()

    Dim b1(1 To 4) As Byte
    Dim b2(1 To 2) As Byte
    Dim lngVal As Long
    Dim intVal As Integer
    Dim i As Integer
   
    For i = 1 To 4
        b1(i) = 255
    Next
   
    'Change the byte order.
    b2(1) = 135
    b2(2) = 105
   
   
   
    CopyMemory lngVal, b1(1), 4
   
    Debug.Print lngVal
   
   CopyMemory intVal, b2(1), 2
   
    Debug.Print intVal
   
    'if the port is an unsigned integer then use
    'cint(105)*256^1+135*256^0

End Sub


0
 
LVL 38

Expert Comment

by:PaulHews
ID: 2766807
sorry should be

'clng(105)*256^1+135*256^0


0
 

Author Comment

by:mtosh
ID: 2767989
Thanks for the quick responses!

The info that you both gave me has gotten me over the coding hump.

Since I asked 3 specific questions:

#1 - how to convert the 32-bit integer to -1
#2 - how to get the IP address
#3 - how to determine the port #

and bhess1 answered #2 and #3 correctly and PaulHews answered #1 and #3 correctly, I'd like to split the points evenly between you two.

I'd like to award bhess1 with 150 points and PaulHews with 150 points.

Now how do I split the points?


Thanks for your help!

Greg
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 2769706
Could try to reduce points for question to 150 and award to bhess.  Then post a new blank 150 point q, for me.

(Don't know if that will work, but it's a suggestion.)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:mtosh
ID: 2770562
I posted the question in the support forum.  Hopefully a tech will split the points up between both of you.  I'll keep an eye on it.

Once again - thanks!
0
 
LVL 3

Expert Comment

by:darinw
ID: 2771920
Community Support has reduced points from 300 to 150
0
 
LVL 3

Expert Comment

by:darinw
ID: 2771921
Reducing points to one half to allow for split.

You can now accept one of the comments in this thread as an answer. To award the other Expert, you can create a new question in this topic area with a title of 'For ExpertName -- 10336916' using that Experts username.

Remember, the Accept Comment as Answer button is in the header of the comment.

For your convenience, you can use this link to create the new question:
http://www.experts-exchange.com/bin/NewQForm?ta=31

darinw
Customer Service
0
 

Author Comment

by:mtosh
ID: 2773309
Thanks for your help!
0
 

Author Comment

by:mtosh
ID: 2773373
bhess1 - I don't know why the point value says 15 instead of 150.  I created another question for you with a point value of 135 (for the remaining points).

PaulHews - I created a question for you so that you can get your 150 points as well.

Thanks.

mtosh
0
 
LVL 32

Expert Comment

by:bhess1
ID: 2773975
The new point value for the question is 1/10th of the original value.  That's how much it would 'cost' some one who had a similar question to get the answer.  Go ahead and delete the other one - I already received the full point value.  Thanks!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now