Solved

C# control remote mouse

Posted on 2010-11-12
10
1,413 Views
Last Modified: 2012-05-10
Hi,
i have a WCF REST service where i NEED to implement a function where it will be accepting X,Y mouse coordinate.

These coordinate will be send from a client with WebGET or WebInvoke then the service will set this coordinate to the local mouse position.

The way i am doing it right now is by sending mouse coordinate on every mouse move by creating different thread for each request.

The problem i am facing is that it is extremely slow and sometime the mouse look like it warp around the screen(on the service computer).

What would be an effective, fluid way to accomplish this?

P.-S. I have to absolutly use WCF REST.

Thanks in advance!
0
Comment
Question by:Enill
  • 5
  • 5
10 Comments
 
LVL 13

Expert Comment

by:AngryBinary
ID: 34125585
You're going to have to expect some delay between updates via a REST service. Starting a new thread and web request for every mouse move event is going to storm both your CPU and network.

I would send all the requests from a single thread that polls the mouse position at a set interval, and sends the requests asynchronously (ignoring the callback). Also, send a serial # (timestamp?) with each request so you can throw out any coordinates received "out of order". The mouse is going to be a bit jumpy by virtue of latency, but I'd wager it turns out a bit smoother.
0
 

Author Comment

by:Enill
ID: 34127668
Hi and thanks for the reply.

I changed my code a little bit to try your suggestion.

All call are made from one thread and i poll the mouse position every 50ms. Honestly it didnt really changed anything.

Now im wondering if it would be faster with WebInvoke instead of WebGet but i doubt it.

When i say its slow, its really terrible and unusable.
0
 
LVL 13

Expert Comment

by:AngryBinary
ID: 34128780
The difference between WebInvoke and WebGet is just the HTTP verb used (GET vs POST), so I wouldn't expect much of a difference either.

It may just be the case that REST (or any other HTTP) isn't going to be suited for your needs. Typically, your application would call for a persistent connection between two machines. The HTTP model is one where a new connection is created, used, and closed for each request - it's a model better suited to a situation where you don't want a limited number of clients tying up the available connections to the server application, and is geared towards serving many clients where scalability is key (like on a web server).

That said, have you profiled the app to find out where the bottleneck is? Can you trace the interval at which requests are actually going out and being received?
0
 

Author Comment

by:Enill
ID: 34128838
Hi,
you are right about WCF REST not being suited for that kind of operation(by design it is not the best).

The bottleneck is clearly in the speed the connection are created, request sent and executed on the other side.

Now i am thinking about figured a way to send direction data. I mean, on the client side i would have a "stick" for exemple, moving the stick inside a circle by pointing it on a direction. This way i could send the wanted direction of the cursor to the server side and the server would start moving the cursor in that direction until it receive a new direction or a StopMoving command.

I guess i will have to do some math there, probably simply stuff but on top of my head i can't remember the Cos/Sin law.
0
 
LVL 13

Expert Comment

by:AngryBinary
ID: 34129219
If you want to calculate rate of change over the x/y axis based on an angle vector, where T is the angle (in radians) and s is speed:

x += s*cos(T);
y += s*sin(T);

Anyway, what is the big picture that you're trying to accomplish?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Enill
ID: 34162717
Hi,
the big picture is actually to move the mouse but i have to use a WCF Rest service.

I am limited by the WCF Rest speed of connection creation everytime i want to send a new position(on mousemove).

I figured it would be best to just elimate the number of total request done by giving a direction to my remote moouse instead of every new point.
0
 
LVL 13

Expert Comment

by:AngryBinary
ID: 34165570
If you send a direction, what you'll find is that the remote mouse doesn't mimic the movements of the local one. I'm not sure how important that is for your application, but it's going seem like the mouse sort of drifts about on its own.

If REST is an absolute must, maybe you can tune up on the service side of the application. How is the service hosted? Can you post your service configuration?
0
 

Author Comment

by:Enill
ID: 34169781
Hi, i am definatly concerned with the problem of "no natural move" but i dont think it would be worst than it is currently.

I am using a Self-Hosted WCF servie in a WPF application actually.

I havent passed much time tuning the configuration(i was too busy with the functionality i guess).

It look something like this:

WebServiceHost host = new WebServiceHost(typeof(My_Class), new Uri("http://localhost:8000/"));
host.AddServiceEndpoint(typeof(My_Class_Interface), new WebHttpBinding(), "");

If you have any tuning suggestions then i am taker.

Thanks!
0
 
LVL 13

Accepted Solution

by:
AngryBinary earned 500 total points
ID: 34171117
Well, I was thinking one possible enhancement might be to run the service in "Singleton" mode (InstanceContextMode = InstanceContextMode.Single). That will slightly speed up the amount of time that a service responds to a request.

Do you think you can post your service code that responds to the mouse events as well?
0
 

Author Comment

by:Enill
ID: 34375866
Wrong button pressed.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now