Structures Send in Binary Form

Z

Zahid

Hi,

I have a number of structures that I want to send using
UDP protocol. How do I convert the structure into
bytes/array of bytes? Using UDP protocol is a MUST - a
Client Requirement.

Am I doing it all wrong? Should I create Classes instead
of these objects- if so how does that help?

In particular How would I send/Convert the array "data()"
into Bytes to send with the structure?

This code is part of an Interface specification that
communicates with a program written C/MFC code.

Thanks in advance
Here is my code:

Public Structure xvnetpkt_type
Public id As Byte
Public prid() As Byte
Public seqno As UInt16
Public length As UInt16 'Length of data
Public code As Char 'reply Code -
Public data() As srvrlogon_type 'Data

Public Sub Initialize()
ReDim prid(2)
ReDim data(MAXDATA)
End Sub

End Structure

Public Structure srvrlogon_type
Public Request As Char
Public ServerNo As UInt16
End Structure

Structure sell_type
Public Request As Char '10 = sell items
Public TableNo As UInt16
Public SplitNo As UInt16
Public nItems As UInt16 'No of ITEMINFO2(max 60)
Public Items() As iteminfo2_type
Public Sub Initialise()
ReDim Items(60)
End Sub
End Structure

Structure iteminfo2_type
Public PLU As UInt64
Public Flags As UInt16
Public quantity As UInt16
End Structure
 
Z

Zahid

Hi,

Here is the code that the C/MFC program uses:

#define MAXDATA 500

typedef struct xvnetpkt_def {
unsigned char id
unsigned char prid[2];
unsigned short seqno;
unsigned short length;
unsigned char code;
char data[MAXDATA];
} XVNetPkt;

typedef struct srvrlogon_def {
unsigned char Request;
unsigned Short ServerNo;
} XV_SRVRLOGON;

Now that youve seen the actual data format what would you
suggest? How shall I go about solving this riddle?

Thanks in advance.
 
Z

Zahid

Hi Jay,

Thanks - but I do need VB.Net code. Do you have VB.NEt
article? Or know of any "Good" converters - i cant find
any good C# to VB.Net converters.

Thanks in advance.
 
J

Jay B. Harlow [MVP - Outlook]

Zahid,
Thanks - but I do need VB.Net code. Do you have VB.NET
article?
Ok. I'm confused, you post C/C++ code but you don't know how to read C#? :-|

Here are a couple samples of your code combined with what the article is
telling you.

Public Interface ISocketObject
Send(ByVal writer As BinaryWriter)
End Interface

Public Structure srvrlogon_type
Implements ISocketObject

Public Request As Char
Public ServerNo As UInt16

Public Sub Send(ByVal writer As BinaryWriter) _
Implements ISocketObject.Send
writer.Write(Request)
writer.Write(ServerNo)
End Sub

End Structure
i cant find any good C# to VB.Net converters.
There are a number available, I do not have a link, hopefully someone else
will post the links.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top