When we're writing socket-related applications, when we're sending soft, complex data, it's possible that the most common thing we do is convert the data from parts to strings, and then connect the strings with a delimiter to send. However, I do not know whether you have thought that there is a problem.
For example, I use # to separate the strings, to look up the server-side based on what the client has entered, and then to return the result, in case of a # in the lookup keyword entered by the user, that will affect our segmentation of the string.
I wonder if you have ever thought that the technique of serialization and deserialization is also used on the socket? First defines a class that encapsulates the data, serializes the object of the class before sending it, and then sends it, receiving the byte stream and then deserializing it to get an object.
This is much better than sending strings alone.
Here's an example of server-side development with WPF, the client is the Windows Store app, and of course I'm just giving examples here, but this can be used for all types of applications, including Windows Phone apps, and the principle is the same.
One, server-side
First we define a class that encapsulates the data, this is demonstrated in a product information class, which is defined on both the server side and the client, to facilitate serialization and deserialization, and you can write to a class library and then both the server side and the client reference the class library.
[DataContract (Name = "Product")]
public class product
{
///<summary>
///Product number
///</summary>
[DataMember (Name =] Product_no ")] public
string Productno {get; set;}
<summary>
///Product name
///</summary>
[DataMember (name = "Product_Name")]
public String ProductName {get; set;}
<summary>
///Product Unit price
///</summary>
[DataMember (Name = "Product_price")]
public Decimal Productprice {get; set;}
}