?
Solved

C# control remote mouse

Posted on 2010-11-12
10
Medium Priority
?
1,483 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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
 

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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

719 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