简体   繁体   English

C# 服务器-客户端实现与 TCP

[英]C# server-client implementation with TCP

I want to create a simple messaging app that uses tcp protocol to communicate, including with multiple people.我想创建一个简单的消息应用程序,它使用 tcp 协议进行通信,包括与多人通信。 Messages get sent to the server, which distributes them to all other clients.消息被发送到服务器,服务器将它们分发给所有其他客户端。 At the moment, I have it fully functioning and it works perfectly - on a local computer and a local network, using the ipv4 address.目前,我已经完全运行它并且它运行良好 - 在本地计算机和本地网络上,使用 ipv4 地址。

After an extensive Google search, I discovered that to communicate from a different network I need to port-forward my server.在进行了广泛的 Google 搜索后,我发现要从不同的网络进行通信,我需要对我的服务器进行端口转发。 However, how do I make my server able to communicate with clients without all the clients port-forwarding?但是,如何使我的服务器能够在没有所有客户端端口转发的情况下与客户端通信? As far as I'm aware, not everybody's device is port-forwarded.据我所知,并不是每个人的设备都是端口转发的。

So, how do I implement this?那么,我该如何实现呢? Is it possible with just C#?是否可以仅使用 C#? Or did I misunderstand something, and port-forwarding isn't really required?还是我误解了某些东西,并且实际上不需要端口转发?

Thanks for all the help.感谢所有的帮助。

Why don't you use SignalR.为什么不使用 SignalR。 I think it will be best for your problem.我认为这将最适合您的问题。

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

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