Adding a VB .NET Shared DLL
|
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.
We use different name for the Solution and the project Name as shown below.
|
Adding a VB .NET Shared DLL
Add new class library named BinData for the shared DLL.
Next, add new Class Library named BinClientVB (for client program).
Well, at this stage we have three projects: BinClientVB, BinData and BinServerVB.
Rename the Class1 to BinData just to reflect the application that to be developed.
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 |
![]() |
|
Select the BinData folder > Right click mouse > Select Build to build the project.
Make sure there is no error. This DLL cannot be executed individually.
If there is no error, the DLL file will be generated as shown below.