在C#与后端的跨平台聊天应用程序的方法 [英] Approach for cross platform chat application with back-end in c#

查看:222
本文介绍了在C#与后端的跨平台聊天应用程序的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个在C#后端跨平台聊天应用
我搜索了一个办法这样做,我发现我可以以http请求,这样做处理我的服务器上,并使用相应的反应。
所以,到现在为止我做了处理程序,可以添加用户,登录,使用数据库存储发送和接收消息。

I want to create a cross platform chat app with backend in c# I searched for an approach to do so and found that I can do so with http requests to handlers on my server and use the response accordingly. So till now I made the handlers which can add users, login, send and receive messages using database for storage.

现在我在做Android客户端为,并获得我需要做在一个特定的时间间隔的HTTP请求的用户信息(3秒)。

Now I am making android client for that and to get messages for user I need to do http requests at a specific interval (3 seconds).

我不觉得它是做一个很好的方法。我提出这个程序对近30000目标受众,他们将能够在单个会话聊天一对一的。

I feel it is not a good approach to do this. I am making this app for a target audience of nearly 30000. They would be able to chat one on one at a single session.

我只是想知道如果我在正确的方向我要去或者有更更好的方式来使用后端聊天应用。

I just want to know if I am going in right direction or There is far more better ways to make chat apps using backend.

我听说过WCF,但我不是,我应该采取什么办法明确。请指导我有关聊天应用程序的方法。

I have heard about wcf but I am not clear with what approach should I take. Please guide me about approaches for chat application.

修改
像什么应用任何著名的聊天应用程序的小工作的一个例子,Facebook的信使将是一个很大的帮助。
谢谢你。

Edit An example of little working of any famous chat app like whats app, facebook messenger would be a great help. Thanks.

推荐答案

您可以使用HTTP做,但我建议使用TCP来代替。有对一个C#基于TCP服务器一个非常坚实的基础的 codereview 的的在这里这将概述如何应对插座对象如何妥善处理的连接。

You could do it with HTTP, but I'd suggest using TCP instead. There's a very solid base for a C# based TCP server on codereview right here which will outline how to deal with Socket objects how to handle connections properly.

中绕了这种方式的主要振作是,你可以将客户端连接到服务器,客户端可以是几乎任何语言,它并没有为C# - 只要语言支持插座,你会没事的。

The main perk of going about it this way is that you can connect your client to the server, and the client can be virtually any language, it doesn't have to be C# - as long as the language supports sockets, you'll be fine.

在此之上,你可以在客户端监听到的服务器,它消除了需要轮询的每两秒钟服务器进行新的消息;当服务器发送它的客户端套接字将接收数据,你可以处理它了,近实时的,而如果你轮询新邮件的服务器通过HTTP每 - 说3秒 - 你将永远结束与你聊天服务的延迟,这是我想你会希望避免的。

On top of that you can have the client listen to the server, which removes the need of polling the server for new messages every couple of seconds; the client socket will receive data when the server sends it, and you can handle it right away, nearly in real-time, whereas if you'd poll the server for new messages over HTTP every - say 3 seconds - you'll always end up with a delay in your chat service, which is something I think you will want to avoid.

查看codeReview的code样品我上面链接,并在阅读了如何插座 S IN C#的工作,TCP如何在保障方面(TCP保证,无论是在发送它最终会在同一顺序的另一边,但在一个包,等不一定),我pretty信心,你就可以做一个优秀的聊天应用如果你把它都很好地利用。

See the code sample on CodeReview I linked above, and read up on how Sockets work in C#, how TCP works in terms of guarantees (TCP guarantees that whatever is sent over it will end up on the other side in the same order, but not necessarily in one packet, etc) and I'm pretty confident you'll be able to make a excellent chat app if you put it all to good use.

编辑:我刚才注意到您帖子的WCF标签。我个人避开它这个具体项目,因为要实现跨平台的支持;尝试将可能为低级别的,你可以为。

I just noticed the WCF tag on your post. I'd personally steer clear of it for this specific project since you want to achieve cross-platform support; try going as low-level as you possibly can for that.

这篇关于在C#与后端的跨平台聊天应用程序的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆