简体   繁体   English

识别具有TCP连接的用户

[英]Identify users with TCP connections

When using C# and TCP, what is the best approach to let a client identify himself using a username and password and then allow multiple packets to be sent from the server to the client and from the client to the server without sending the username & password each time? 使用C#和TCP时,最好的方法是让客户端使用用户名和密码来识别自己的身份,然后允许从服务器向客户端以及从客户端向服务器发送多个数据包,而无需分别发送用户名和密码时间? Thread for each user? 每个用户的线程? Token that's sent with each packet? 每个数据包都发送了令牌吗?

Also, how to make sure that only the client is able to read the data that the server is sending & vice versa? 另外,如何确保只有客户端才能读取服务器正在发送的数据,反之亦然? Just using SSLStream ? 仅使用SSLStream

You are too low-level. 您太低级了。 What you need is an application protocol on top of TCP that supports authentication. 您需要的是TCP之上的支持身份验证的应用程序协议 One of the options may be HTTP. 选项之一可以是HTTP。 When working with .NET, the commonly used approach is leveraging WCF (Windows Communication Foundation) . 使用.NET时,常用的方法是利用WCF(Windows Communication Foundation) You can build a WCF service that will require authentication, such as “username and password” as you mention, while still being flexible about what underlying means of communication are used (eg SOAP and HTTP, or plain TCP and WCF's custom binary protocol, etc.). 您可以构建一个需要身份验证的WCF服务,例如您提到的“用户名和密码”,同时仍可以灵活地使用所使用的底层通信方式(例如SOAP和HTTP,或普通的TCP和WCF的自定义二进制协议等)。 )。

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

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