< C# Binary Client Socket Program Example | Main | VB .NET Binary Client-Server Socket Project Example 2 >

 


 

Chapter 4 Part 8:

Serialization

 

 

What do we have in this chapter 4 part 8 (Windows Server 2003)?

  1. VB .NET Binary Socket Server Program Example

  2. Adding a VB .NET Shared DLL

  3. Adding the VB .NET Binary Socket Client Program Example

  4. The VB .NET Shared DLL Project

 

 

VB .NET Binary Socket Server Program Example

 

In this practice we create a single solution with three projects (server, client and shared DLL) on Windows 2003 Server Standard Edition using Visual Studio 2008 Pro. Create a new Class Library project.

 

VB .NET Binary Socket Server Program Example - invoking the New Project page in VS 2008

 

We use different name for the Solution and the project Name as shown below.

 

VB .NET Binary Socket Server Program Example - Creating a new class library project

 

Adding a VB .NET Shared DLL

 

Add new class library named BinData for the shared DLL.

 

VB .NET Binary Socket Server Program Example - adding a new project to the existing solution

 

VB .NET Binary Socket Server Program Example - adding a new class library to the existing project

 

Adding the VB .NET Binary Socket Client Program Example

 

Next, add new Class Library named BinClientVB (for client program).

 

Adding the VB .NET Binary Socket Client Program Example - adding a new class library project to the existing project

 

Well, at this stage we have three projects: BinClientVB, BinData and BinServerVB.

 

The VB .NET Shared DLL Project

 

Rename the Class1 to BinData just to reflect the application that to be developed.

 

Adding the VB .NET Binary Socket Client Program Example - renaming the class name

 

Add the following codes to the BinData.vb

 

' This namespace contains the BinData class which is the object serialized between

' the client and server applications also contained in this project. This sample

' illustrates serialization over a socket stream as well as how to serialize common

' data between two applications. The assembly containing the serialized data must

' be present for both client and server.

Imports System

 

Namespace BinData

 

    ' This class is referenced by the BinDataClass which is the type of object

    ' that will be serialized. This illustrates that all classes referenced

    ' must have the Serializable attribute set.

    <Serializable()> _

    Public Class BinDataSubClass

        Public SubField1 As Integer

 

        ' Simple constructor for the class which initialized the properties

        Public Sub New()

            Console.WriteLine("I'm in Sub New() of BinDataSubClass...")

            SubField1 = -1

        End Sub

 

        ' Prints the class values to the console

        Public Sub Print()

            Console.WriteLine("I'm in Sub Print() of BinDataSubClass...")

            Console.WriteLine("BinDataSubClass.SubField1 = {0}", SubField1.ToString())

        End Sub

    End Class

 

    ' This is the class which will be serialized over the socket connection. It

    ' contains a reference to another class which also has the Serializable attribute

    ' set.

 

    <Serializable()> _

    Public Class BinDataClass

 

        Public Field1 As Integer

        Public Field2 As String

        Public SubClass As BinDataSubClass

 

        ' Simple constructor that initializes the member properties.

        Public Sub New()

            Console.WriteLine()

            Console.WriteLine("I'm in Sub New() of BinDataClass...")

            SubClass = New BinDataSubClass()

            Field1 = 1234

            Field2 = "Field2"

        End Sub

 

        ' Prints the class members to the console

        Public Sub Print()

            Console.WriteLine()

            Console.WriteLine("I'm in Sub Print() of BinDataClass...")

            Console.WriteLine("BinDataClass.Field1 = {0}", Field1.ToString())

            Console.WriteLine("BinDataClass.Field2 = {0}", Field2)

            SubClass.Print()

        End Sub

    End Class

End Namespace

 

Adding the VB .NET Binary Socket Client Program Example - building the class library independently  

 

Select the BinData folder > Right click mouse > Select Build to build the project.

 

Adding the VB .NET Binary Socket Client Program Example - invoking the Build command menu

 

Make sure there is no error. This DLL cannot be executed individually.

 

Adding the VB .NET Binary Socket Client Program Example - Build messages as can be seen through the Output windows of the VS 2008

 

If there is no error, the DLL file will be generated as shown below.

 

Adding the VB .NET Binary Socket Client Program Example - the generated DLL file ready to be used

 

 

 


 

< C# Binary Client Socket Program Example | Main | VB .NET Binary Client-Server Socket Project Example 2 >