简体   繁体   English

快速提问TCP / IP .Net远程处理

[英]Quick question TCP/IP .Net Remoting

I have a client application where i collect data and store it in a class Packet structure. 我有一个客户端应用程序,我在其中收集数据并将其存储在类Packet结构中。 Can I send the object of this class to my Server application?..Both application run on different machines connected by LAN network. 我可以将此类的对象发送到我的Server应用程序吗?两个应用程序都在通过LAN网络连接的不同计算机上运行。

In .Net Remoting, where Object is instantiated in Server and Objref is shared with the Client. 在.Net Remoting中,对象在服务器中实例化,而Objref与客户端共享。 Now i have this object of class Packet as the remotable object, which is used as Client activated objects. 现在,我将Packet类的该对象作为可移动对象,用作客户端激活的对象。 The object is created when the client activates it. 客户端激活对象后即创建该对象。

public class Packet : MarshalByRefObject {
        public int svrnumber;
        public string svrname;
        [NonSerialized]
        public static IObserver Observer;

        public void MessageString(object value) {
                Observer.Notify(value);
        }

        public static void Attach(IObserver observer) {
            Observer = observer;
        }
    }

I refer the Pack(Object) of this class in client side and assign value. 我在客户端引用此类的Pack(Object)并分配值。

            Pack.svrname = "Bob";
            Pack.svrnumber = 123456;

            sample = (Object)Pack;

Pass this sample object to Notify. 将此示例对象传递给Notify。 I recieve this sample object at the server through the Notify function and unbox it to get my values. 我通过Notify函数在服务器上接收了此示例对象,并将其拆箱以获取我的值。

By while i am calling the function MessageString, I get an exception as security restrictions Objref is not accessible!! 在我调用MessageString函数时,由于安全限制Objref无法访问,我得到了一个异常!

Also tell me whether there is any other approach to this issue.. Or should i use the SocketProgramming approach where i convert all my class values to bytes and then send across to server and then re-assign them. 还请告诉我是否有其他方法可以解决此问题。或者我应该使用SocketProgramming方法,将所有的类值转换为字节,然后发送给服务器,然后重新分配它们。

Thanks. 谢谢。

我将使用WCF方法,已完成此操作,并不意味着可以进行远程处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM