简体   繁体   中英

creating a one on one chat inside an asp.net website

i would like to create a facebook like one on one chat within an asp.net website, but i cant figure out the mechanism or how it would work.

so far i only have a database table for it designed like this:

    id | user1 | user2 | datetime | message

how do i get started, thanks.

The most efficient method to build a chat in asp.net is to use a IHttpAsyncHandler and ajax requests.

Here is a completely working project that implements this , along with ajax.

An async request allows you to delay the response of a request till an external event occurs.
A user makes a call to this handler and waits till someone sends him a message.
Messages are delivered as soon as you send them to a user. On receiving a message the client makes another request and waits for the next message.
This is a lot more efficient than polling the site to check if messages have arrived.

Using the async handler also ensures that no asp.net threads are wasted waiting while a user waits for messages to come.

This ensures that you chat can scale well even as the number of users of the site goes up.

我会考虑将Signal R用于此类功能-请参阅本指南,以实现与信号r的聊天功能-应该消除开发过程中的许多麻烦http://geekswithblogs.net/jeroenb/archive/2011/12 /14/signalr-starter-application.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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