Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format of messages through winsock session...

Status
Not open for further replies.

Phailak

Programmer
Apr 10, 2001
142
CA
Hail,

I wonder if anyone can help me with this, I've been at it for some time now. I have a booklet for an API for an application we use. What I need to do is connect to a server, send messages (through winsock I guess) and get replies from the server. What I don't understand is how to send the data so that it corresponds to the format shown in the booklet. There has to first be a header, then the body of the message. Does anyone have any idea of what I'm talking about and if so, can anyone help me out if I give them the specifics involved...

Phailak
 
I suppose you could probably use a byte array to produce the header, then a string for the body, and send them by using .SendData in a loop, once for each byte in the array, and once for the string...

Winsock is not my area of expertise, but I am getting somewhat more familiar with it.
 
this sounds a bit like some things I have done.
If none of the regular experts will object and you post the details I will give it a shot.
"trust me. I know what I'm doing" Terry (cyberbiker)
 
Hail,

I'll give you what I have in the doc concernig let's say the first message is for Login, user is cars and password scar.

First thing they ask is to establish a connection with the server, which I believe I have accomplished through Winsock. Once a session is established, I have to send a message to the server in order to log in, if all goes well, it should reply with a message that tells me I'mm looged in.
Ok, they call there message for login as follows: SCHAPI_MSG_LOGIN
In answer to this either we get SCHAPI_MSG_LOGGEDIN or a message error SCHAPI_MSG_ERROR/SCHAPI_ERR_INVALID

First they ask that every message body be preceeded by a message header which is constructed as so:

The length and format of the header is fixed. The length of the body is contained in the header. The content of the body is variable. Headers are fixed at 8 bytes in length.

1 byte -> Flags
1 byte -> Code (see message structure below for code number)
2 bytes-> Length (see message structure below for code number)
4 bytes-> RFU (Reserved for futur use)
and then follows the body (the actual message below)

it also says that body lengths will always be in multiples of four bytes

it also specifies something I don't understand, the integer data fields of the header are in big-endian format (i.e. MSB first)???

When the underlying network and network protocols are packet oriented, it is recommended that the header and body each be sent as a packet. That is, neither header nor body should be broken across packets nor should the two be combined into a single packet ??? (how could that be?)

The server does not operate in packet-synchronous mode. Instead, it reads data in byte stream format. This means that even if a client sends message headers and message bodies as packets, the server may still lose message boundaries. Regardless, it is recommended that client apps send messages headers and message bodies as discrete packets.

Data representation

Data fields in the messages are made up of 3 basic data types: integers, strings and bitmaps.

Integers are either 1,2,4 or 8 bytes long. Can be signed or unsigned. Always stored in big-endian format (MSB)

Strings are variable length sequences of US-ASCII characters. Since all fields are of a fixed size, unused bytes in a string must contain zeros. A string field will always be followed by a one byte field labeled zero. This field should always contain NULL character (0x00)

Sign in / Password -> All US-ASCII codes from 0x20 to 0x7e are legal

SCHAPI_MSG_LOGIN

Code = 14
Support= Required
Direction= Query
Length = 52 bytes

0-7 8 9-16 17 18-51
8 for 1 for 8 for 1 for 34 for
signin zero pwd zero rfu (futur use)

That's all I got

As for the actual code with winsock, I'm far from an expert so any insight on the winsock procedure would be appreciated.
I know this is a lot of blah blah so let me know if there's too much stuff or if I might be missing something

Phailak
 
I will have to think on this a bit. I have no idea what "Big Endian Format" is sounds a bit like my ex wifes rear, but doubtful that is the case. Terry (cyberbiker)
 
There are two types of integers - big and little endian... While the wife comment brings a smile to my face, that is not it...

Simply put it's the order of the bytes in memory. If you have 0x1234 (big endian) it would read in little endian as 0x3412. I believe by default Windows uses big endian, but I would have to check.
 
Hail,

Woah you're awful, speaking of an ex-flame like that, although I can sympathise.
Take your time, if you can figure it out, my hat's off to you. They just threw this on my lap and stared. I'm still at the beginning of the project, if I can't figure this out, there's not much I can do after.
Thanx again for considering it. Let me know if you have questions

Phailak
 
hope somebody else out there knows more than I do.
At first I thought this was similar to some stuff I had worked on in another language, but now do not think it is too close.
I will play with it a bit tonight and see if I can relate it to anything I know. But hope someone can provide better answers. I am curious now! Terry (cyberbiker)
 
Hail,

Well thanx for the attempt. If you get something tonight, let me know. I appreciate you taking a look at it though

Phailak

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top