Ich kann mir nicht vorstellen das Du nur einen port je richtung und je Anwendung öffnen kannst. Sollte es so sein, wäre ein Rinmgprotokoll notwendig ...
Mein Client sieht so aus:
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Ipc
Public Class Form1
Dim SendChannelName As String = "localhost:9090"
Dim ReceiveChannelName As String = "localhost:9091"
Dim obj As SharedInterfaces.ICommunicationService = DirectCast( _
Activator.GetObject(GetType(SharedInterfaces.ICommunicationService), _
"ipc://" & SendChannelName & "/rObj"), _
SharedInterfaces.ICommunicationService)
Dim ipcCh1 As System.Runtime.Remoting.Channels.Ipc.IpcServerChannel = New _
IpcServerChannel(ReceiveChannelName)
Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
obj.SaySomething(Date.Now.ToString)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
ChannelServices.RegisterChannel(ipcCh1, False)
RemotingConfiguration.RegisterWellKnownServiceType(GetType( _
CommunicationService), "rObj", WellKnownObjectMode.Singleton)
End Sub
End Class
Public Class CommunicationService
Inherits MarshalByRefObject
Implements SharedInterfaces.ICommunicationService
Delegate Sub SaySomething_Delegate(ByVal Text As String)
Public Sub SaySomething(ByVal Text As String) Implements _
SharedInterfaces.ICommunicationService.SaySomething
If My.Application.OpenForms(0).InvokeRequired = True Then
My.Application.OpenForms(0).Invoke(New SaySomething_Delegate( _
AddressOf SaySomething), New Object() {Text})
Else
My.Application.OpenForms(0).Text = Text
End If
End Sub
End ClassMein Server so:
Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Ipc
Public Class Form1
Dim SendChannelName As String = "localhost:9091"
Dim ReceiveChannelName As String = "localhost:9090"
Dim obj As SharedInterfaces.ICommunicationService = DirectCast( _
Activator.GetObject(GetType(SharedInterfaces.ICommunicationService), _
"ipc://" & SendChannelName & "/rObj"), _
SharedInterfaces.ICommunicationService)
Dim ipcCh1 As System.Runtime.Remoting.Channels.Ipc.IpcServerChannel = New _
IpcServerChannel(ReceiveChannelName)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
ChannelServices.RegisterChannel(ipcCh1, False)
RemotingConfiguration.RegisterWellKnownServiceType(GetType( _
CommunicationService), "rObj", WellKnownObjectMode.Singleton)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
obj.SaySomething(Date.Now.ToString)
End Sub
End Class
Public Class CommunicationService
Inherits MarshalByRefObject
Implements SharedInterfaces.ICommunicationService
Delegate Sub SaySomething_Delegate(ByVal Text As String)
Public Sub SaySomething(ByVal Text As String) Implements _
SharedInterfaces.ICommunicationService.SaySomething
If My.Application.OpenForms(0).InvokeRequired = True Then
My.Application.OpenForms(0).Invoke(New SaySomething_Delegate( _
AddressOf SaySomething), New Object() {Text})
Else
My.Application.OpenForms(0).Text = Text
End If
End Sub
End Class |