Easiest for two way communication over the internet using C#

天大地大妈咪最大 提交于 2019-12-10 09:53:10

问题


What do I use for two way communication over the internet without the necessity to open ports on the client side?

Users won't agree to open ports and do port forwarding on the client side although everything is possible on the server side.

But,I need to accomplish two way communication..

How do I go about achieving this?

It doesn't matter whether its WCF or remoting or webservices... I just need a quick and fast way to just get the concept to work out and distribute the application.

ofcourse,it's going to be through the internet.

Please help.. Thanks

Edit : Please note that i need to connect multiple clients and maintain a session for each client.


回答1:


WCF supports duplex HTTP bindings.

As long as the initiating client can access the service, a callback contract can be defined to call the client. It simply keeps the HTTP connection once the client has initiated it.




回答2:


It depends what you want to do. Duplex WCF can work, but through NAT and Proxies it becomes somewhat "iffy" because it depends on the client opening a WCF endpoint and maintaining the connection.

I wrote a beginners guide to WCF callbacks a while ago - it's simple enough to do, but you'll need to test it a lot, from various client setups.




回答3:


Connect via TCP (raw sockets, or higher implementation) to a your central server.
Your server should have an application that listens to a specific, well known, TCP port.
Each client connects to your server, using the specific port, and "logs in".
Write an application protocol above the TCP (authentication, session management, etc.), and there you have it, since a TCP connection, once established, works for both directions.



来源:https://stackoverflow.com/questions/1318229/easiest-for-two-way-communication-over-the-internet-using-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!