客户端-服务器tcp查询 [英] client-server tcp query

查看:96
本文介绍了客户端-服务器tcp查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!
如何将消息从客户端发送到客户端服务器体系结构中的另一个客户端?
我试图在c + +中实现一种算法,出于某种原因,我想将消息从每个节点发送到相邻节点,并进一步实现..m迷惑了如何执行dis,因为我以前从未在c中进行过网络编程.我已经研究了一些代码,但是它们要么从服务器发送到客户端,要么从客户端发送到服务器...有人可以帮忙吗?

hello!!
how can we send a message from a client to another client in a client server architecture ?
i am trying to implement an algorithm in c++ in which i want to send message from each node to the neighbouring nodes for some reason and to further implementation ..i m confused how to do dis because i have never worked with network programming before in c. i have studied some codes but they are either sending message from server to client or client to server...can someone help please?

推荐答案

您已经发布了此问题此处 [
You already posted this question here[^]; please post in one forum only.


有人做了此事,所以请考虑使用一些基于TCP的协议.它们很多,例如RPC,DCOM,CORBA,SOAP ...但是,世界上没有比重新发明轮子更有趣的事情了.因此,这不是问题.你可以自己的.出于学习目的,这是一个很好的练习.
Someone done this berore, so just think of using some TCP based protocol. There are many of them, such as RPC, DCOM, CORBA, SOAP... But there is no more interesting thing in the world than reinventing the wheel. So, not a problem. You can your own. For study purposes it is very good exercise.


在传统的客户端服务器中,您无法直接从客户端向客户端发送消息.
这仅仅是因为2个客户端之间没有TCP/UDP/etc连接.

您的服务器必须以某种方式在2个客户端之间中继消息.
您可以这样操作:
1)在从客户端到服务器的消息中,有一个简单的int或bool字段,意思是目的地",例如,服务器1,客户端0.
2)如果服务器收到一条带有此字段的消息,表明该消息是针对另一个客户端的,则将其按原样"发送到与该客户端的连接中,而无需进行处理-例如,它充当简单的数据中继.

Client1->服务器-> Client2
Client2->服务器-> Client1

如果您有两个以上的客户端,则可以根据需要轻松扩展此客户端.您可以支持消息广播"(一个客户端与所有其他客户端对话)或点对点"(一个客户端与另一个客户端对话)的情况.

顺便说一句,在TCP/IP之上建立了对等协议,例如.在OSI模型的应用程序层上,但每个端同时都有一个客户端和一个服务器部分".
In classic client server, you cannot send a message from client to client directly.
This is simply because there is no TCP/UDP/etc connection between 2 clients.

Your server has to relay messages between 2 clients somehow.
You can do it this way:
1) In messages from client to server, have a simple int or bool field meaning "destination", for example, 1 for server, 0 for client.
2) If the server gets a message with this field indicating it is for another client, send it "as is" into the connection with that client WITHOUT PROCESSING - e.g. it acts as a simple data relay.

Client1->Server->Client2
Client2->Server->Client1

If you have more than 2 clients, you can easily extend this as needed. You can support situations where your messages are "broadcast" (one client talks to all other clients) or "point to point" (one client talks to one other client).

By the way, there are peer to peer protocols built on top of TCP/IP eg. on app layer of OSI model, but still, each side has a client and a server "part" simultaneosly.


这篇关于客户端-服务器tcp查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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