客户端到客户端消息传递在套接字编程中 [英] Client to client messaging in socket programming

查看:113
本文介绍了客户端到客户端消息传递在套接字编程中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个项目,这是一个基于WinSock的C ++中的服务器 - 客户端应用程序。我已经做了任何需要在服务器和客户端之间的通信,我能够发送和接收之间的消息。



现在我需要知道如何完成客户端到客户端消息传递部分以及如何完成工作。我只知道,例如,如果客户端A和客户端B需要彼此通信,客户端A必须发送消息到服务器,服务器接收消息并发送到客户端B.



如果这是正确的方法,请帮助我知道服务器应该知道接收器(在这种情况下是客户端B)的任何东西?



如果我没有清楚解释我的问题,请让我知道。



任何帮助。

一种方法是让客户端在实际服务器上进行一些通信之后充当服务器。你需要创建一个你的协议。话虽如此:



1-客户端A:-Hey,服务器!告诉客户B创建一个comm服务器,以便我可以直接与他通信。



2-服务器:-Hey,客户端B!启动服务器实例并告诉我连接属性,以便我可以转发客户端A,以便他可以连接到您。



3-客户端B:-Hey,服务器! 。我准备好接受客户端A的连接请求。这是我的连接属性...



4-服务器: - 客户端A!这里是客户端B的连接属性。取它或离开...我完成了。



5-客户端A:-Hey,服务器B!我可以连接吗?



这是协议..所以任何客户端首先发起一个请求到服务器,包括消息类型我,请求连接到客户端X..。服务器命令客户端x,客户端x响应,服务器中继响应启动器客户端...还应该实现错误处理,拒绝策略或一些其他的事情,你可以想到为了管理整个协议。


I'm working on a project which is a server-client application based on WinSock in C++. I've done whatever needed for communicate between the server and the client that I am able to send and receive messages between them.

Now I need to know how to accomplish the client-to-client messaging part and how the work must be done. I only know that for instance if Client A and Client B need to communicate with each other, the client A must send the message to the server, server receives the message and send it to client B.

If this is the proper approach please help me to know how the server should know anything of of the receiver (which is the Client B in this case)?

Please let me know if I haven't explained clearly my problem.

Any help is appreciated.

解决方案

One way to accomplish this is have one of the client to act as a server after some communication over actual server. You need to create a protocol of yours. That being said:

1- Client A: -Hey, Server!. Tell the Client B to create a comm server so I can communicate directly with him.

2- Server: -Hey, Client B!. Start a server instance and tell me the connection properties so i can relay it Client A, so he can connect to you.

3- Client B: -Hey, Server!. I'm ready to accept the connection request for Client A. Here's my connection properties...

4- Server: -Client A!! Here the connection properties of Client B. Take it or leave it... I'm done..

5- Client A: -Hey, Server B!.. Can i connect?..

That is the protocol.. So any client first initiates a request to server that includes the message type of "me, requesting to connect to client x..". Server commands the client x, client x responses, server relays the response to initiator client... And also you should implement the error handlings, denial policies or some other things you can think of in order to manage the whole protocol.

这篇关于客户端到客户端消息传递在套接字编程中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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