If this sounds like the way SignalR works, that is no accident. On the server, we keep track of connections and pending messages for connections, and if you reconnect within the timeout limit (a minute or so), you won’t miss any changes. ![]() We still have to deal with errors and network hiccups, we do that by aborting the events connection are retrying. This is what the events connection looks like: We can then issue commands for this connection, in the sample above you can see those commands for watching a particular document and finally stopping altogether. The first part is a sequential id that is used strict to help us debug things “1st request, 2nd request” are a log easier than J0JP5 or some guid. ![]() Did you note that we have this “1/J0JP5” connection id? This is generated on the client (part an always incrementing number, part random) for each connection id. So we actually have a problem here, how do we configure this connection? Now, HTTP connections are only good for one request/response. Once that is done, on the client side you need to read from the server in an async manner and raise events whenever you got a full response back.įor our purposes, we used new lines as response marker, so we would read from the stream until we got a new line, raise that event, and move on. In order to get this to work, you have to make sure to turn off bufferring in IIS (HttpListener doesn’t do buffering) and when running in Silverlight, you have to disable read buffering. The very first thing that happens is that we make a request to /changes/events?id=CONNECTION_ID, the server is going to keep this connection open, and whenever it has something new to send to the client, it will use this connection. This is the Fiddler trace that you see when running a simple subscription test: How it works is a tiny bit complex, so let us see if I can explain with a picture. Given our needs, this is the solution that we choose in the end. This is basically the client downloading from the server, but instead of having the entire request download in one go, the server will send events whenever it has something. ![]() It seems like a waste and I think we can do better.įinally, we have the notion of a streamed download. ![]() Long Polling is an option, but I don’t like it. WebSockets would have been a great options, but they aren’t widely available yet, and won’t work well without special servers, which I currently don’t have. Writing you own TCP socket server is a lot of fun, but debugging why something went wrong is not. It is easy to work with, there are great tools (thanks, Fiddler!) around to do that and you can debug/test/scale it without major hurdles. We are relying on HTTP for all things, and I like HTTP. We need to be able to get notified by the server whenever something interesting happened. I promised that I’ll talk about the actual implementation details of how RavenDB deal with changes, after moving from SignalR to our own implementation.įirst, let us examine the problem space.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |