将变量传递给项目 [英] Passing variable between to projects

查看:104
本文介绍了将变量传递给项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我在TCP协议上使用服务器和客户端之间的通信。


我打开了一台新服务器所以现在我有了客户端的一个项目,以及两个服务器项目的解决方案。我想要做的是在主服务器上收到消息时将字符串变量传递给辅助服务器。


每个服务器正在侦听不同的端口,以便客户端知道哪个服务器他正在通过更改端口号来发送。

我想做的事情是,当主服务器获得一个新的tcp客户端时,他将为他打开一个类并对待他的消息,它是工作。当客户端在另一个端口号中发送消息时,另一个服务器将为他打开该类并处理
消息,并且它正在工作。


我的问题是在两者之后类打开我想从主服务器的类传递一个字符串到辅助服务器的类。因为在获取字符串的值之前已经打开了类,所以我无法在
的构造函数中传递它。


对解决方案的任何建议?

解决方案

您的术语有点令人困惑,因此不清楚哪些项目与服务器有关。还不清楚"主要"是否为"主"。服务器和"其他"服务器服务器是在同一个进程,不同的进程相同的机器或不同的
机器完全。最后,不会创建或打开类。在您新建类时会创建类的实例。看起来你有一个类类型,但有多个实例(每个服务器一个)。


如果你需要在同一个进程中的对象之间进行通信,你可以使用适合你需求的架构。使用共享数据对象,数据库,域事件等。


如果需要在不同进程中的对象之间进行通信,那么您将需要使用某种类型的IPC。如果您支持HTTP,WCF在这里可能很有用,因为REST API也可以。在同一台机器上,您也可以使用命名管道。


如果您只需要在某些数据的2个实例之间进行通信,那么像共享数据管理器对象这样简单的东西也可以正常工作。 / p>


Hello,

Im using comunication between server and client on TCP protocol.

I opened a new server so now I have one project of the client, and a solution with two projects of servers. What I want to do is to pass a string variable to the secondary server when I receive a message in the main server.

Each server is listening on a differnet port so the client knows which server he is sending to, by changing the port number.
The thing I want to do is that when the main server gets a new tcp client he will open a class for him and treat his message, and it's working. When the client sends a message in the other port number the other server will open the class for him and treat the message, and it's working.

My problam is that after both classes are open I want to pass a string from the class of the main server to the class of the secondary server. Because the class is already opened before I get the value of the string, I can't pass it in the constructor of the class.

Any suggestions for a solution?

解决方案

Your terminology is a little confusing so it is unclear what projects have to do with the # of servers. It is also unclear whether the "main" server and the "other" server are in the same process, different processes same machine or different machines entirely. Finally, classes aren't created or opened. Instances of classes are created when you new them up. It seems like you have a single class type but multiple instances (one per server).

If you need to communicate between objects in the same process you can use architecture that fits your needs ranging from using a shared data object, database, domain events, etc.

If you need to communicate between objects in different processes then you'll need to use IPC of some sort. WCF could be useful here as could a REST API if you're supporting HTTP. On the same machine you could also use named pipes.

If you simply need to communicate between 2 instances of some data then something as simple as a shared data manager object may work as well.


这篇关于将变量传递给项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆