简体   繁体   English

C#,WCF,想创建一个聊天应用程序,我应该使用什么绑定? 也许一些例子?

[英]C#, WCF, want to make a chat application, what binding should I use? maybe some examples?

I am looking forward to make a sort of a chat application using C# and WCF, yet before I start I wanted to clear a few things, so that I don't get carried in the wrong direction. 我期待使用C#和WCF制作一个聊天应用程序,但是在开始之前,我想清除一些事情,以免出现错误的方向。 :) :)

  • the application should be able to both make event ( send messages ) and listen to events ( receive messages ), therefor if I understand it right, the application should be both the client and the server at once? 应用程序应该既可以发出事件(发送消息)又可以监听事件(接收消息),因此,如果我理解正确的话,该应用程序应该同时是客户端和服务器?

  • what binding should I use? 我应该使用什么绑定? If I understand right, basicHttp binding hard to configure and is used when a WCF app needs to connect to non-WCF app? 如果我理解正确,那么WWW应用程序需要连接到非WCF应用程序时就很难配置basicHttp绑定? While for connecting two WCF apps its better to use NetTcpBinding? 虽然要连接两个WCF应用程序,最好使用NetTcpBinding?

  • how would this applications find each other, considering that they are running on different machines? 考虑到它们在不同的计算机上运行,​​这些应用程序如何相互找到? should there be a central server, to which the app would connect first, saying "I'm user123, my IP is that and that, I'm free for chat" and look for other user IP addresses there? 是否应该有一个中央服务器,该应用程序将首先连接到该中央服务器,并说“我是user123,那是我的IP,那是免费的,我可以聊天”,并在那里寻找其他用户IP地址? Or is there some other ways for apps to find each other without the central server? 还是在没有中央服务器的情况下,应用程序还有其他方法可以互相查找?

  • maybe you could direct me to some examples or tutorials on this topic? 也许您可以指导我一些有关此主题的示例或教程? ( tried googling, no luck ). (尝试使用谷歌搜索,没有运气)。

Thanks! 谢谢! :) :)

If your peers (machine that can operate as a client & server) are going to be behind NATs/firewalls then you will have a very very tough time building a chat application using WCF. 如果您的同龄人(可以充当客户端和服务器的计算机)位于NAT /防火墙之后,那么使用WCF构建聊天应用程序将非常困难。 If the peers will all be on the same network WCF is workable. 如果对等点都在同一网络上,则WCF是可行的。

To write a chat application from scratch using WCF you will be re-inventing the wheel. 要使用WCF从头开始编写聊天应用程序,您将重新发明轮子。 Why not employ an existing protocol that's been designed precisely for the purpose such as XMPP. 为什么不采用专门针对此目的而设计的现有协议,例如XMPP。 There are XMPP libraries around for .Net. .Net周围有XMPP库 You will need a central server but if you use XMPP you could feasibly piggyback onto one of the many existing free servers. 您将需要一个中央服务器,但是如果您使用XMPP,则可以轻松地搭载到许多现有的免费服务器之一上。

There is no right and wrong answer to your question - it all depends on what you require. 您的问题没有对与错的答案-一切都取决于您的要求。 You then can choose the best architecture for your needs, and then the best technology for that architecture. 然后,您可以选择适合您需要的最佳体系结构,然后再选择适合该体系结构的最佳技术。

There are two things to consider - how will users find people to chat to, and then once they have found someone - how do the applications connect to each other. 有两点需要考虑-用户如何找到要聊天的人,然后一旦找到某人-应用程序如何相互连接。

For users to find each other, you either need to connect to a central server, which will then show a list of all connected users, or users need to enter the IP address of the person they want to chat to. 为了使用户能够彼此找到对方,您要么需要连接到中央服务器,然后它将显示所有已连接用户的列表,或者用户需要输入要与之聊天的人的IP地址。 Note that some firewalls will block incoming connections in this second case, so this may not be feasible in some cases. 请注意,在第二种情况下,某些防火墙将阻止传入连接,因此在某些情况下这可能不可行。

Next, once you have found the person you wish to chat to, you need to decide whether messages will route directly to the other user, or if you want to continue to go through a central server. 接下来,找到要聊天的人后,您需要确定消息是否将直接路由到其他用户,或者是否要继续通过中央服务器。

If you choose to go through a central server, then your application will be functioning as a client, and will therefore pass through firewalls without a problem. 如果您选择通过中央服务器,则您的应用程序将作为客户端运行,因此可以毫无问题地通过防火墙。 However if you connect directly to the other user, both copies of the application will be acting as a client and a server (P2P topology), and therefore firewalls may be an issue. 但是,如果直接连接到另一个用户,则应用程序的两个副本都将充当客户端和服务器(P2P拓扑),因此防火墙可能是一个问题。 Having said that, you could designate one of the applications to be a server, with the other acting as a client, in which case only the server side needs to worry about the firewall. 话虽如此,您可以将其中一个应用程序指定为服务器,而另一个应用程序作为客户端,在这种情况下,只有服务器端才需要担心防火墙。

Without knowing exactly what you are trying to achieve, it is hard to recommend which architecture will work best for you. 在不确切了解您要实现的目标的情况下,很难推荐哪种架构最适合您。

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

相关问题 如何在C#IF语句中使用此示例“ return”? - How do I make use of this examples “return”, in a C# IF statement? 我想让图片框在C#中发生碰撞该怎么办? - What should I do when I want to make my picturebox collide in c#? 我有一个 JSON 想在我的 Unity C# 应用程序中使用,其中某些属性过载 - I have a JSON that I want to use in my Unity C# application where some properties are overloaded 我想制作我自己的 c# 调试器——该怎么做呢? 我应该使用什么工具? - I want to make my own c# debugger - how would one do that? What tools should I be using? 编写需要嵌入加密数据库的C#桌面应用程序。我应该使用什么类型的数据库? - Writing a C# desktop application that needs to embed an encrypted database. What type of database should I use? 我想在我的C#应用​​程序中进行以下curl调用 - i want to make the following curl call in my C# application 我应该为我的应用程序使用Managed C ++或C#吗? - Should I use Managed C++ or C# for my application? C#windows应用程序 - 希望将我的业务和数据层保存在单独的机器中并使用WCF访问它 - C# windows application - want to keep my business and data layer in a seperate machine and use WCF to access it C#中的聊天应用程序 - Chat application in C# C#聊天应用程序 - C# Chat application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM