[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1509
  • Last Modified:

C# control remote mouse

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
Enill
Asked:
Enill
  • 5
  • 5
1 Solution
 
AngryBinaryCommented:
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
 
EnillAuthor Commented:
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
 
AngryBinaryCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
EnillAuthor Commented:
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
 
AngryBinaryCommented:
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
 
EnillAuthor Commented:
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
 
AngryBinaryCommented:
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
 
EnillAuthor Commented:
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
 
AngryBinaryCommented:
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
 
EnillAuthor Commented:
Wrong button pressed.
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now