Hello,
I want to connect a system in LAN and i want to access
that.When ever i am moving a mouse in my desktop the
similar thing have to happend in the another system in
which i have connected.
I need coding for this in c# and .NET .
any one please help me.It is very urgent to me
Advance thanks.

my email id:manojkumarchallagundla@gmail.com



Hello, I want to connect a system in LAN and i want to access that.When ever i am moving a mouse ..

Answer / Banafsha Siddiqui

For real-time mouse movement synchronization between two systems in LAN using C#, you can use WCF (Windows Communication Foundation) with callback mechanism. Here's a simple example:

1. Install the 'Service Library' and 'NetFX 4.0 Client Profile' project templates from Visual Studio.
2. Create a WCF service project containing the code for getting mouse position:

```csharp
using System;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.Windows.Forms;

[ServiceContract]
public interface IMouseService
{
[OperationContract]
void UpdateMousePosition(int x, int y);
}

[DataContract]
public class MousePosition
{
[DataMember]
public int X { get; set; }
[DataMember]
public int Y { get; set; }
}

public class MouseService : IMouseService
{
public void UpdateMousePosition(int x, int y)
{
var client = OperationContext.Current.GetCallbackChannel<IMouseService>() as IMouseService;
if (client != null)
client.UpdateMousePosition(x, y);
}
}
```
3. Create a WCF client application that listens for the mouse movement event and calls the service when triggered:

```csharp
using System;
using System.ServiceModel;
using System.Windows.Forms;

namespace MouseClient
{
class Program
{
static void Main()
{
var client = new DuplexClient<IMouseService>("net.tcp://localhost/MouseService");
Application.AddMessageFilter(new MouseEventFilter(client));
Application.Run();
}
}
}

class MouseEventFilter : IMessageFilter
{
private readonly Action<int, int> _updateCallback;

public MouseEventFilter(Action<int, int> updateCallback)
{
_updateCallback = updateCallback;
}

public bool PreFilterMessage(ref Message message)
{
if (message.Label == "MouseUp" || message.Label == "MouseMove")
{
var args = (MouseEventArgs)message.Properties["APS_EventArg"];
_updateCallback(args.X, args.Y);
return true;
}
return false;
}
}
}
```
4. Register the service with net.tcp binding and host it in IIS.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Dot Net Remoting Interview Questions

Explain the difference between the registerwellknownservicetype(), registerwellknownclienttype(), registeractivatedservicetype() and registeractivatedclienttype() in .net?

1 Answers  


Explain marshalling and its types in .net remoting

0 Answers  


What are the ways to renew lifetime leases of objects?

1 Answers  


Explain the types of .net remoting?

1 Answers  


What are the security features in .net remoting?

1 Answers  


What is the difference between the RegisterWellknownServiceType(), RegisterWellknownClientType(), RegisterActivatedServiceType() and RegisterActivatedClientType() in .net?

1 Answers  


How can you debug failed assembly binds?

1 Answers  


How to directly call a native function exported from a dll?

1 Answers  


What is unmanaged code and will CLR handle this kind of code or not ?

1 Answers   DELL,


Can you pass SOAP messages through remoting?

1 Answers  


What is a Windows process?

1 Answers  


Explain the hierarchial description of remoting?

1 Answers  


Categories