To create the QueryTrackerServerListener server, you need to create the Server class that registers the QueryProvider remoting object on a TCP channel and listens for the request for that remoting object made by the Query Tracker client application.
Listing 4-9 shows the code for the Server.vb that defines the Server class:
Imports System.Runtime.Remoting Imports System.Runtime.Remoting.Channels Imports System.Runtime.Remoting.Channels.Tcp 'This class defines the server listener that registers the remoting object on a TCP channel Public Class Server Dim tcp As TcpChannel Dim cs As ChannelServices Public Sub RegisterObject() 'Creating a new TcpChannel tcp = New TcpChannel(8080) 'Registering the new TcpChannel cs.RegisterChannel(tcp) Dim objQueryProvider As New QueryTrackerRemotingObject.QueryProvider 'Registering the service provided by QueryProvider Remoting Business object RemotingConfiguration.RegisterWellKnownServiceType(objQueryProvider.GetType, _ "QueryProvider", WellKnownObjectMode.SingleCall) 'This message box confirms that the server listener is running MsgBox("Server Running") End Sub End Class Public Class start Public Shared Sub Main() Dim server As New Server server.RegisterObject() End Sub End Class
Download this Listing .
In the above listing, the RegisterObject() method creates a TCP channel and listens for the request for the QueryProvider remoting object at port 8080. The server starts before any executive requests the remoting object to retrieve and update queries into the database.