Sockets for sending/receiving mouse movement

elektrobank

Member
Joined
Aug 11, 2008
Messages
19
Programming Experience
10+
I am creating a simple server application that will listen for incoming mouse coordinates and then move the mouse accordingly. So basically it's like a very simple VNC server without the screen display. I have this basic part working. The problem is that response time is really bad. It seems like the server is not receiving the data fast enough to be able to move the mouse so that it appears to be in sync with the movement on the client machine. I'm using a buffer size of 32, and just sending my commands from the client as the same length every time so that I'm processing them as fast as they are sent. When they come in, I add them to a queue, then have a separate thread that processes the movement in the queue. I figured this was the fastest way, but it doesn't seem to be fast enough. Clearly there is a better way of doing this that I'm not seeing. Any suggestions?

My code looks something like this:
VB.NET:
Public Sub dataArrival(ByVal ar As IAsyncResult)

            Dim bytesRead As Integer = handler.EndReceive(ar)

            If bytesRead > 0 Then

                content = Encoding.ASCII.GetString(state.buffer, 0,
bytesRead)

                eventQueue.Add(content)

                handler.BeginReceive(state.buffer, 0,
StateObject.BufferSize, 0, New AsyncCallback(AddressOf dataArrival),
state)

            end if

end sub
 
Asynchronous is the most accurate way one can go about using sockets. Maybe your probably is not in the sending or receiving, it could be some unknown factor in you code, perhaps the way your getting and setting the coordinates. Loops will also slow down the application, try threading (assuming you’re using a loop). But if you still believe that your issue is with the sockets, than you can try UDP which is must faster than TCP (although I really don’t think it would make a difference in this case).

Other than that, you could upload your application so that one can run a proper diagnose, that if you don’t mind.
 
Back
Top