473,396 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Structures Send in Binary Form

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
Nov 20 '05 #1
4 2517
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.
-----Original Message-----
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
.

Nov 20 '05 #2
Zahid,
The "easiest" way is to use a BinaryReader & BinaryWriter (in the System.IO
namespace) to read & write the structures, manually field by field, to the
UDP Network Stream.

The following articles shows how to do the above with C#.
http://msdn.microsoft.com/library/de...rp09182003.asp

If you need help converting to VB.NET, let us know.

Hope this helps
Jay

"Zahid" <mr******@hotmail.com> wrote in message
news:0b****************************@phx.gbl...
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

Nov 20 '05 #3
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.
-----Original Message-----
Zahid,
The "easiest" way is to use a BinaryReader & BinaryWriter (in the System.IOnamespace) to read & write the structures, manually field by field, to theUDP Network Stream.

The following articles shows how to do the above with C#.
http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dncscol/html/csharp09182003.asp
If you need help converting to VB.NET, let us know.

Hope this helps
Jay

"Zahid" <mr******@hotmail.com> wrote in message
news:0b****************************@phx.gbl...
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

.

Nov 20 '05 #4
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

"Zahid" <mr******@hotmail.com> wrote in message
news:00****************************@phx.gbl... 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.
-----Original Message-----
Zahid,
The "easiest" way is to use a BinaryReader &

BinaryWriter (in the System.IO
namespace) to read & write the structures, manually

field by field, to the
UDP Network Stream.

The following articles shows how to do the above with C#.
http://msdn.microsoft.com/library/default.asp?

url=/library/en-us/dncscol/html/csharp09182003.asp

If you need help converting to VB.NET, let us know.

Hope this helps
Jay

"Zahid" <mr******@hotmail.com> wrote in message
news:0b****************************@phx.gbl...
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

.

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fatih BOY | last post by:
Hi, I want to send a report from a windows application to a web page like 'report.asp' Currently i can send it via post method with a context like local=En&Username=fatih&UserId=45&Firm=none...
3
by: Matt Laver | last post by:
Hi, I have a binary file that I'm currently reading byte by byte using code similiar to: string FileName = @"c:\myFile.dat"; FileStream fs = new FileStream(FileName, FileMode.Open,...
2
by: phyzics | last post by:
I am porting an application from C++ to C#, and am having trouble finding a way to quickly and efficiently write structures to a binary file. In C++ this is trivial because all that is necessary is...
3
by: Usenet User | last post by:
I am trying to read (and then save) a binary file which has certain data structures in it. (The file is in propritetary format produced by a 3rd party MFC application.) I know that those data...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
13
by: jehugaleahsa | last post by:
Hello: I got tired of trying to find good implementations of collections and other data structures in C#. So, I started implementing my own. However, data structures is a wholly different...
3
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I'm trying to write an array of structures named myStructArray to a binary file and later on read it back. Although I could complete the entire project in C in about 2 minutes, I...
1
by: deepaks85 | last post by:
Dear All, I want to send some data through a form with Multiple attachment in an HTML Format. I have tried it but it is not working for me. I am able to send data without attachment but with the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.