I need to stream data to a TCP-server and havnt done it before. The data should be in binary frame format. I googled and found this tutorial which I think describes what I need to do:
http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient(v=vs.71).aspx
But I dont know how to create the data in the format needed so I can send it in the correct way. It should be in this format:
Field|Offset| Type | size(octets)
id | 0 |unsign int| 1
name | 1 |Byte Array| 40
grade| 41 |sign float| 8
Example:
Field| Data | InBytes |
id | 133 | 133 |
name | 247 | 247 0 |
grade| 0 | 0 |
Whats the data type I should store the int, byte array, float in and where do I specify offsets and size and finally how should it be sent to the server (in the example they only send a byte array).
A C#-example of how to send data like this using the code in the link provided above would be appreciated.
To represent the data to be serialized (and deserialized) you can use a struct and set the proper metadata, so the CLR do the rest for you. Like others said here you will need to deal with the packet reception on the end point. Also you’ll have to consider the charset expected by the receiver, since you have a string field in your data. The following code is an example on how you can implement the struct to convert your managed data to a binary format, with comments.
Usage:
You already have the packet, now you’ll need to deal with the packet reception on the receiver. That part you don’t need to do all by hand, you can use some tools, like @jgauffin said.