syntax for remoting on ipcchannel
I have a beginners question
Sofar I have added two windowsform applications(server and client) and a libraryclass project to the solution. I have added System.Runtime.Remoting references to both projects and refferences to the remoteobject class.
Now I need some help to fill in the blanks.
I kept the client and server code in a separate class apart from the form class
Goal is to add "Hello world" to the listbox on the clientform if a button is pressed and a counter
I have trouble retaining the last value of the counter getID?
TIA, Richard
I have a beginners question
Sofar I have added two windowsform applications(server and client) and a libraryclass project to the solution. I have added System.Runtime.Remoting references to both projects and refferences to the remoteobject class.
Now I need some help to fill in the blanks.
I kept the client and server code in a separate class apart from the form class
Goal is to add "Hello world" to the listbox on the clientform if a button is pressed and a counter
I have trouble retaining the last value of the counter getID?
VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] knpConnect_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] knpConnect.Click[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] testObj [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SampleObject[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] str [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = testObj.HelloWorld()[/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ListBox1.Items.Add(str)[/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Label3.Text = [/SIZE][SIZE=2][COLOR=#a31515]"Counter: "[/COLOR][/SIZE][SIZE=2] & (Convert.ToString(testObj.getID))[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] SampleRemotingClient[/SIZE]
[SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] main()[/SIZE]
[SIZE=2][COLOR=#008000]'// Create a channel for communicating w/ the remote object[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] clientChannel [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] IpcClientChannel = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] IpcClientChannel[/SIZE]
[SIZE=2]ChannelServices.RegisterChannel(clientChannel, [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#008000]'// Register and create an instance of the remote object[/COLOR][/SIZE]
[SIZE=2]RemotingConfiguration.RegisterWellKnownClientType( _[/SIZE]
[SIZE=2]GetType(SampleObject), _[/SIZE]
[SIZE=2][COLOR=#a31515]"ipc://hello/helloworld"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff][/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
VB.NET:
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System[/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] SampleObject[/SIZE]
[SIZE=2][COLOR=#0000ff]Inherits[/COLOR][/SIZE][SIZE=2] MarshalByRefObject[/SIZE]
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] lastID [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 0[/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] HelloWorld() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][SIZE=2][COLOR=#a31515]"Hello world"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] getID() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE]
[SIZE=2]lastID = lastID + 1[/SIZE]
[SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][SIZE=2] (lastID)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE]
VB.NET:
[SIZE=2][SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System[/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Runtime.Remoting[/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Runtime.Remoting.Channels[/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Runtime.Remoting.Channels.Ipc[/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] SampleRemotingServer[/SIZE]
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] main()[/SIZE]
[SIZE=2][COLOR=#008000]' // Create an instance of a channel[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] serverChannel [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] IChannel = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] IpcChannel([/SIZE][SIZE=2][COLOR=#a31515]"hello"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]ChannelServices.RegisterChannel(serverChannel, [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#008000]'// Register as an available service with the name HelloWorld[/COLOR][/SIZE]
[SIZE=2]RemotingConfiguration.RegisterWellKnownServiceType( _[/SIZE]
[SIZE=2][COLOR=#0000ff]GetType[/COLOR][/SIZE][SIZE=2](SampleObject), _ [/SIZE]
[SIZE=2][COLOR=#a31515]"HelloWorld"[/COLOR][/SIZE][SIZE=2], _[/SIZE]
[SIZE=2]WellKnownObjectMode.Singleton)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE]
[/SIZE]
TIA, Richard
Last edited: