如何从服务器中的客户端池中识别客户端

如何从服务器中的客户端池中识别客户端

本文介绍了如何从服务器中的客户端池中识别客户端-设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我有一个正在使用的客户端/服务器库.服务器可以接受来自客户端的多个连接.在每次对Accept()的调用时,如果成功,则将客户端套接字的句柄推入映射,并使用一个假定的唯一ID作为键.这样,当服务器以后要向特定客户端发送消息时,它将使用此ID查找客户端.

Okay, so I have a client/server library that I'm working. The server can accept multiple connections from clients. At every call to Accept(), if successful, the handle to the client's socket is pushed to a map, with a supposed unique ID as a key. So that when the server want to send a message to a specific client later on, it will find the client using this ID.

我的问题:每个客户的唯一ID是什么? IP地址不可行,因为多个客户端可以来自同一IP地址.如果没有,谁能建议其他好的设计.谢谢

My question: What can be the unique ID for every client? IP address is not posssible as multiple clients can come from the same IP address. If not, can anyone suggest some other good design. Thanks

插图:

ClientSocket workerSock = Server.Accept();

Map.Add(workerSock);

       Map
____________________
|Key   | Value     |
|------------------|
| ?    |workerSock1| ------------------------ client application 1
|------------------|
| ?    |workerSock2| ------------------------ client application 2
|------------------|
| ?    |workerSock3| ------------------------ client application 3
--------------------

方案:服务器希望发送到特定的客户端,因此它必须具有一些ID.

Scenario: Server wants to send to a specific client, so it has to have some ID.

推荐答案

我们在创建网络库 networkComms时解决了类似的问题.网.我们的解决方案是通过IPEndPoint( MSDN ),Guid( MSDN )和连接类型,例如TCP,UDP等.在高级连接握手期间交换Guid,以便两端都知道对方.

We solved a similar problem when creating the network library networkComms.net. Our solution was to keep track of peers by IPEndPoint (MSDN), Guid (MSDN) and connection types, e.g. TCP, UDP etc. The Guid are exchanged during the high-level connection handshake so that both ends are aware of the other.

这篇关于如何从服务器中的客户端池中识别客户端-设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 15:18