Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Synchronous Operation
Avatar
mayprog #1
Member since Mar 2006 · 61 posts
Group memberships: Members
Show profile · Link to this post
Subject: Synchronous Operation
I have a project where the only thread needed, besides the UI thread, will be that of AgsXmpp.
Because of the asynchronous management of your library i am into many problems trying to solve locks.
I wonder, do you think it would be too difiicult to convert this into a synchronous one?
I saw how you handle sockets asynchronously and i think it could be managed synchronous from me.
DO you think i should try to make it synchronous or it will be too difficult?
Also, if i convert it to synchronous and Receive() data by using timers, what do you rhink about its speed?
Do you have any tips to give me about where i should look in order to make it syncrhonous (eg Socket and NetworkStream, elsewhere?)
Thanks in advance!
Avatar
Alex #2
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

it should be no big deal to make the library synchronous. All the socket code relies in ClientSocket.cs. But i dont understand what the advatage of synchronous sockets would be. The only disadvantage of async is that you have to invoke all events which udate the GUI because SWF is not Thread safe.
I don't understand the second part with timers. Do you mean making the IqGrabber and Grabber classes synchronous too with timers?

Alex
Avatar
mayprog #3
Member since Mar 2006 · 61 posts
Group memberships: Members
Show profile · Link to this post
Well first of all thanks for the reply.

The problem is that i have build all my logic mapped into your events.
So, as long as the Data Access Layer is seperated from the UI, i dont have on the DAL a Control to Invoke or BeginInvoke.
Thats why, all my DAL functions must have locks in order to make sure that no data is simultaneously writting and reading.
Another problem is that by using BeginInvoke ( i think ) there is no guarantie that the events will be called by the order they are fired!Isn't that right?

Imagine the following situation, i want to know when my roster has come in order to send my presence. I also want the ui to be ready for this (control created etc).
If i catch the RosterEnd event and sent the SendMyPresence, then i will be having presence messages before the Controls of the roster are created (they will be in the midle of the creting process). That is a problem of mine. Of course, a solution would be to call Invoke synchrounously, but then all the "async" processing is gone.
Thats the reasons for trying to make it Single Threaded.

Do you think there could be a better approach?

About timers.... i wanted to say that i was going to use a timer with a small interval in order to do the Socket.Receive synchronously from the UI when that timer fires tick.
Do you thing this will slow down the application much and also that it is the proper way of doing this?

Thanks again!
This post was edited on 2006-05-19, 20:04 by mayprog.
Avatar
Alex #4
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

did you take a look at HTTP polling? PollClientSocket-cs is using timers to poll in intervals from the servers. And it doesnt make the connection much slower. But i wouldn't use timers to call Recieve on a "normal" socket. I would use a NetworkStream in synchronous mode then. You can Read the Data in a NetworkStream in a Loop until the stream is closed and Read() returns -1. If no Data is available in the stream the Read blocks, so its synchrounous.

Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP RSS