C# 监听 TCP 端口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10626902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# Listen TCP Port
提问by lucky
I want to listen a TCP port. The scenario:
我想听一个 TCP 端口。场景:
SIP server, and client-program. The SIP server may use port 5010 to listen and establish multiple connections. The client connects from his pc to the server via port 5010.
SIP 服务器和客户端程序。SIP 服务器可以使用 5010 端口来侦听和建立多个连接。客户端通过端口 5010 从他的 PC 连接到服务器。
When a packet is received on that port, an event must be triggered on the client PC.
当在该端口上接收到数据包时,必须在客户端 PC 上触发一个事件。
Any ideas where to start?
任何想法从哪里开始?
回答by Almo
Assuming you're working in .NET, look at TcpClient and TcpListener.
假设您在 .NET 中工作,请查看 TcpClient 和 TcpListener。
Here's the MSDN documentation on TcpListener: https://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener(v=vs.110).aspx
这是关于 TcpListener 的 MSDN 文档:https://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener(v =vs.110).aspx
回答by platon
Start from the TcpListener ClassMSDN topic. It contains even the example which should be helpful to you.
从TcpListener 类MSDN 主题开始。它甚至包含应该对您有所帮助的示例。

