Last post Sep 03, 2015 03:00 PM by LarzaJean
Sep 01, 2015 05:12 PM|LarzaJean|LINK
I'm fairly new to SignalR and I have a question that I haven't been able to find any answer for :
- I've seen that a persistent connection is established between the client and the server thanks to signalr. But let's admit that we have an ASP.NET MVC application that lists books that you can borrow. Once the book is borrowed by someone else, signalR
send a notification for clients to remove the line on the screen.
What if a client is connecting to the application and while the persistent connection is being established, someone borrows a book. The user won't receive a notification because the establishment of the connection isn't finished yet and the book is in the
list of items that was retrieved from the server.
Is there any way to "fix" this kind of "accident" ?
Thanks for your answers.
Sep 02, 2015 03:53 AM|Fei Han - MSFT|LINK
Welcome to ASP.NET forum.
Firstly, you should check if the book user would like to borrow is available before updating status of this book in database when someone is borrowing the book. So that we can ensure the integrity of the data.
Secondly, you could query for all available books from database after someone borrowed the book, then you could send new book list to all clients and refresh the clients instead of removing book which is borrowed from client list.
Sep 03, 2015 03:00 PM|LarzaJean|LINK
Hi Fei Han,
Thanks for the advice and this fast reply. I am checking book status when someone is trying to borrow it !
As you said, I cuold query for all available books after someone borrowed the book and refresh the whole list. However, this doesn't solve my problem.
If a user request all books available (let's say there's five books available), the server will send the list to the client but if someone borrows a book while the page is loading in the client's browser, in the end he will see 5 books when in fact there's
only 4 of them available.
The list will refresh when someone borrows a book but meanwhile, the list on the client's screen is still false !