简体   繁体   English

处理具有相同IP的多客户端中的服务器的接收值

[英]Handle receive values from server in multi clients with same IP

I want to connect to server with multiple clients and some clients in the same computer and same IP address. 我想连接到具有多个客户端的服务器和同一计算机中的一些客户端以及相同的IP地址。 I mean, in my application, in the different forms, user can connect to server and get value from server in the same time. 我的意思是,在我的应用程序中,用户可以以不同的形式连接到服务器并同时从服务器获取值。 I read more about multi clients but all of them was about multi clients in different computer or different applications. 我阅读了有关多客户端的更多信息,但它们都是关于不同计算机或不同应用程序中的多客户端。 I think, i handle received values from server in client side with a dictionary that save connected clients and every received value set in a queue, and if not run any received value then get a data from queue and etc. but i don't know how can i know this received values is for which request from client. 我认为,我处理客户端服务器收到的值,其中包含保存连接客户端的字典和队列中设置的每个接收值,如果没有运行任何接收到的值,则从队列等获取数据,但我不知道我怎么知道这个收到的值是客户的请求。 I try solve this problem around 3 days and i couldn't. 我试着解决这个问题大约3天,我不能。 Please if you can help me 如果你能帮帮我的话

For sure it's better to specify your Platform, Environment and ... when you have a question about it, Well in general cases there's no different. 当你对它有疑问时,最好指定你的平台,环境和......一般来说,没有什么不同。 BTW, I assume it's .Net. 顺便说一句,我认为它是.Net。

.Net platform .Net平台

If you do socket programming and you wanna recognize different requests from multiple clients in same Computer/IP the Client.RemoteEndPoint from TcpClient class give you that. 如果您进行套接字编程,并且您想要识别来自同一计算机/ IP中的多个客户端的不同请求, Client.RemoteEndPoint来自TcpClient类的Client.RemoteEndPoint为您提供。 Actually, it's consists of IP:Port and It's a key to get you know how it works separately, which in each programming languages with high probability it would be like that because in the same computer each endpoint needs to have same IP but different port. 实际上,它由IP组成:端口和它是一个关键,让你知道它是如何分开工作的,这在每种编程语言中很有可能就是这样,因为在同一台计算机中每个端点需要具有相同的IP但不同的端口。 So even in the same computer you would have this as an ID (IP:Port) and can use it as the key within your dictionary. 因此,即使在同一台计算机中,您也可以使用它作为ID(IP:端口),并可以将其用作字典中的密钥。

General cases 一般情况

In some general ways for each platform or without usages of built-in frameworks you could consider your server like a WebServer (I see It's more complex) but how a WebServer would process each request by itself even if they are 2 different sessions in 2 browsers from 1 computer and 1 port? 对于每个平台的一些通用方法或没有内置框架的用法,您可以将服务器视为WebServer(我看它更复杂),但WebServer如何自行处理每个请求,即使它们是2个浏览器中的2个不同会话从1台电脑和1个端口? So you should implement your code in that way. 所以你应该以这种方式实现你的代码。 Actually, you should put some extra information on each request and give them some unique pieces of information (ID) on your own. 实际上,您应该在每个请求上添加一些额外的信息,并自己给它们一些独特的信息(ID)。 Then you could identify them from each other. 然后你可以互相识别它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM