none
初学者请教Remoting的问题 RRS feed

  • 问题

  • 一个基于Remoing的小程序,客户端在连接服务器后调用服务器的一个方法,这个方法将引发所有客户的一个事件.(广播)

    问题1:在本地测试的时候可以正常运行,但把服务器端放到服务器上就不行了.在引发客户端事件的时候就卡死掉了.是不是服务器在引发客户端事件时被防火墙之类的档住了还是我的发布代码有问题?


    问题2:在局域网内的某台机器启动了一个服务,局域网外的机器要如何才能连接到这台机器?IP是已知的.比如公网IP地址是:123.123.123.132 内网IP是:192.168.1.2,服务端口是123.在局域网外要如何连接?当然不能用手动设置路由器的办法


    以下是程序代码,在本地测试没问题.一些没用的代码就不贴了,看起来麻烦

    VB.NET code
    '接口 Public Interface IRemote Sub Login(ByVal Client As Client) Sub SendMessage(ByVal str As String) End Interface '实现 Public Class ServiceBase Inherits MarshalByRefObject Implements RemoteIDataBase Private Clients As List(Of CLient) Public Sub New() Clients = New List(Of Client) End Sub Public Sub Login(ByVal Client As CLient) Implements IRemote.Login Me.Clients.Add(Client) AddHandler GetMessage, AddressOf Client.OnResveiMessage End Sub Public Sub SendMessage(ByVal str As String) Implements IRemote.SendMessage RaiseEvent GetMessage '就是在这里卡住了 End Function Public Event GetMessage(ByVal Str As String) End Class 'Client类 <Serializable()> Public Class RemoteCredential Inherits MarshalByRefObject Public Event GetMessage(ByVal Str As String) Public Sub OnResveiMessage(ByVal Message As String) Dim thread As New Threading.Thread(AddressOf RaiseMessageEvent) thread.Start(Message) End Sub Public Sub RaiseMessageEvent(ByVal Obj As Object) RaiseEvent GetMessage(Obj) End Sub End Class '主窗口 Public Class Form Inherits Form Public Sub New() InitializeComponent() '侦听 Dim provider As New Channels.BinaryServerFormatterSinkProvider() provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full Dim resiveChn As New Channels.Tcp.TcpChannel(0) Channels.ChannelServices.RegisterChannel(resiveChn, False) Try '建立主机 Dim IPProvider As New aspdServiceBase.ClientIPServerSinkProvider() IPProvider.Next = provider Dim tcpchannel1 As New Channels.Tcp.TcpServerChannel("xx1", 61234, IPProvider) Channels.ChannelServices.RegisterChannel(tcpchannel1, False) RemotingConfiguration.RegisterWellKnownServiceType(GetType(aspdServiceBase.RemoteServiceBase), "xx1", WellKnownObjectMode.Singleton) Me.Text = "主机" Catch ex As Exception Me.Text = "从机 " End Try End Sub Private WithEvents Login As aspdNet.RemoteCredential Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Db = Activator.GetObject(GetType(IRemote), "tcp://" & Me.TextBox1.Text & ":61234/xx1") Login = New Client Db.Login(Login) End Sub Private Sub GetMessage(ByVal str As String) Handles Login.GetMessage If Me.InvokeRequired Then Me.Invoke(New EventGetMessage(AddressOf RefStr), str) End If End Sub Private Sub RefStr(ByVal str As String) Me.ListBox1.Items.Add(str) End Sub end Class
    • 已移动 Paul Zhou 2011年6月30日 9:37 (发件人:.NET Framework 一般性问题讨论区)
    2011年6月29日 8:02