将服务器连接到另一台服务器 [英] connecting server to aother server

查看:212
本文介绍了将服务器连接到另一台服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..



我在我的机器上运行C ++客户端/服务器应用程序,并且它正常工作,甚至客户端也可以发送消息给服务器。我的下一步是让我的服务器连接到另一台服务器,这可能吗??????



问候

Hi..

I''m running a C++ Client/Server application on my machine, and its working properly, and even the client can send messages to the server. And my next step is to make my server connect to another server, is this possible??????

regards

推荐答案

是的,但听起来你想要的是点对点应用程序而不是客户端服务器应用程序。无论如何,只需在一个进程中运行客户端和服务器,就可以做到这一点。一个简单的对等应用程序可能在其主线程上运行服务器的一个实例,并启动一个单独的客户端线程来为它发现的每个其他服务器运行客户端代码,因此它成为服务器和N个客户端或者可能是服务器而且只是1客户端取决于你正在做什么。

流程模型中的1个服务器N个客户端可以通过使用众所周知的端口来完成服务器的听插座。每次服务器收到新连接时,例如从10.50.83.65开始,它在自己的进程中启动一个客户端线程,尝试连接到众所周知的服务器端口上的源10.50.83.65处的服务器。

有很多方法可以做到这一点,代码项目和更远的地方点对点上的大量文章和样本。
Yes, but it sounds like what you want is a peer to peer application rather than a client server application. Anyway you can do this just by running the client as well as the server in one process. A simple peer to peer application might run one instance of the server on its main thread and launch a separate client thread to run the client code for each of the other servers it discovers so it becomes a server and N clients or perhaps a server and just 1 client depending on what you''re doing.
The 1 server N clients in a process model can be done by using a well known port for the server''s listening socket. Each time the server recieves a new connection e.g. from 10.50.83.65 it starts a client thread in its own process that tries to connect back to the server at the source 10.50.83.65 on the well known server port.
There are many ways to do this and lots of articles and samples on peer to peer both on Code Project and further afield.


这篇关于将服务器连接到另一台服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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