The ability to send custom objects and encrypt the sent objects when sent, compression is an important feature of the NETWORKCOMMS v3 framework.
Refer to the source Code Exampleconsole engineering documents
The syntax for sending custom objects using the Networkcomms V3 framework is as follows:
New CustomObject ("ben"); Networkcomms.sendobject ("Message""127.0.0.1 " 10000, mycustomobject);
If you are using the Protobuf.net serializer, then the syntax for the custom object is as follows:
[Protocontract]Private classcustomobject{[Protomember (1)] Public intAge {Get;Private Set; } [Protomember (2)] Public stringName {Get;Private Set; } /// <summary> ///parameterless constructor required for Protobuf/// </summary> protectedCustomObject () {} PublicCustomObject (stringNameintAge ) { This. Name =name; This. Age =Age ; }}
For some classes that do not support serialization, such as serialization of the image class, some conversions are performed as follows:
[Protocontract] Public classimagewrapper{/// <summary> ///Private Store of the image data as a byte[]///This would be populated automatically if the object is serialised/// </summary>[Protomember (1)] Private byte[] _imagedata; /// <summary> ///The image name/// </summary>[Protomember (2)] Public stringImageName {Get;Set; } /// <summary> ///The public accessor for the image. this'll be populated///automatically when the object is deserialised. /// </summary> PublicImage Image {Get;Set; } /// <summary> ///Private parameterless constructor required for Deserialisation/// </summary> PrivateImagewrapper () {}/// <summary> ///Create a new imagewrapper/// </summary> /// <param name= "ImageName" ></param> /// <param name= "image" ></param> PublicImagewrapper (stringImageName, image image) { This. ImageName =ImageName; This. Image =image; } /// <summary> ///before serialising This object convert the image to binary data/// </summary>[Protobeforeserialization]Private voidSerialize () {if(Image! =NULL) { //We need to decide how to convert our image to its raw binary form here using(MemoryStream InputStream =NewMemoryStream ()) { //For basic image types The features is part of the. NET FrameworkImage.Save (InputStream, Image.rawformat); //If We wanted to include additional data processing here//such as compression, encryption etc we can still use the features provided by Networkcomms.net//e.g. see dpsmanager.getdataprocessor<lzmacompressor> ()//Store The binary image data as bytes[]_imagedata =Inputstream.toarray (); } } } /// <summary> ///When deserialising the object to convert the binary data back to an Image object/// </summary>[Protoafterdeserialization]Private voidDeserialize () {MemoryStream ms=NewMemoryStream (_imagedata); //If We added custom data processes We have the perform the reverse operations here before//trying to recreate the image object//e.g. dpsmanager.getdataprocessor<lzmacompressor> ()Image=Image.fromstream (MS); _imagedata=NULL; }}
Original: http://www.networkcomms.net/custom-objects/
Www.networkcomms.cn Finishing
Networkcomms V3 's Custom object