Moin, ich habe einen WebSocketServer basierend auf der Alchemy Libairy und diesen mit einem Global-Mouse-Hook verbunden. Soweit sogut.
Nun muss ich wenn zB die Linke Maus betätigt wird etwas vom WebSocketServer an den verbundenen Client senden - und das bekomm ich irgendwie nicht nicht.
Das Mausevent wird ausgelöst und von daaus muss ich dann ja irgendwie senden. Ganz unten in einer extra Class wird auch was gesendet - das funktioniert auch nur bekomm ich das nicht in die obere Class übertragen.
Wär nett wenn sich das jemand angucken könnte
MfG
Wenn ich es mit dem unten stehenden Code versuche get das Programm einfach aus.
Und wenn ich es so probiere nekomm ich : Keine Überladung für die send-Methode nimmt 1 Argument an.
Nun muss ich wenn zB die Linke Maus betätigt wird etwas vom WebSocketServer an den verbundenen Client senden - und das bekomm ich irgendwie nicht nicht.
Das Mausevent wird ausgelöst und von daaus muss ich dann ja irgendwie senden. Ganz unten in einer extra Class wird auch was gesendet - das funktioniert auch nur bekomm ich das nicht in die obere Class übertragen.
Wär nett wenn sich das jemand angucken könnte
MfG
C#-Quellcode
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Threading;
- using System.Collections.Concurrent;
- using Alchemy;
- using Alchemy.Classes;
- using MouseKeyboardLibrary;
- namespace SampleApplication
- {
- public partial class HookTestForm : Form
- {
- MouseHook mouseHook = new MouseHook();
- public HookTestForm()
- {
- InitializeComponent();
- }
- private void TestForm_Load(object sender, EventArgs e)
- {
- mouseHook.MouseDown += new MouseEventHandler(mouseHook_MouseDown);
- mouseHook.Start();
- var aServer = new WebSocketServer(8100, System.Net.IPAddress.Any)
- {
- OnReceive = OnReceive,
- OnSend = OnSend,
- OnConnected = OnConnect,
- OnDisconnect = OnDisconnect,
- TimeOut = new TimeSpan(0, 5, 0)
- };
- aServer.Start();
- }
- public void mouseHook_MouseDown(object sender, MouseEventArgs e)
- {
- // Context.Send("asd");
- // AddMouseEvent(
- // "MouseDown",
- //e.Button.ToString(),
- // e.X.ToString(),
- // e.Y.ToString(),
- //""
- //);
- }
- void AddMouseEvent(string eventType, string button, string x, string y, string delta)
- {
- listView1.Items.Insert(0,
- new ListViewItem(
- new string[]{
- eventType,
- button,
- x,
- y,
- delta
- }));
- }
- public static void OnConnect(UserContext aContext)
- {
- MessageBox.Show("Client Connected From : " + aContext.ClientAddress.ToString());
- // Create a new Connection Object to save client context information
- // var conn = new Connection { Context = aContext };
- // Add a connection Object to thread-safe collection
- //OnlineConnections.TryAdd(aContext.ClientAddress.ToString(), conn);
- }
- public static void OnReceive(UserContext aContext)
- {
- try
- {
- MessageBox.Show("Data Received From [" + aContext.ClientAddress.ToString() + "] - " + aContext.DataFrame.ToString());
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message.ToString());
- }
- }
- public static void OnSend(UserContext aContext)
- {
- // MessageBox.Show("Data Sent To : " + aContext.ClientAddress.ToString());
- }
- public static void OnDisconnect(UserContext aContext)
- {
- // -------------- "Client Disconnected : " + aContext.ClientAddress.ToString();
- // Remove the connection Object from the thread-safe collection
- // Connection conn;
- //OnlineConnections.TryRemove(aContext.ClientAddress.ToString(),out conn);
- // Dispose timer to stop sending messages to the client.
- //conn.timer.Dispose();
- }
- private void TestForm_FormClosed(object sender, FormClosedEventArgs e)
- {
- // Not necessary anymore, will stop when application exits
- //mouseHook.Stop();
- //keyboardHook.Stop();
- }
- }
- public class Connection
- {
- public System.Threading.Timer timer;
- public UserContext Context { get; set; }
- public Connection()
- {
- this.timer = new System.Threading.Timer(this.TimerCallback, null, 0, 1000);
- }
- private void TimerCallback(object state)
- {
- try
- {
- // Sending Data to the Client
- // Context.Send("[" + Context.ClientAddress.ToString() + "] " + System.DateTime.Now.ToString());
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
- }
Wenn ich es mit dem unten stehenden Code versuche get das Programm einfach aus.
C#-Quellcode
- public partial class HookTestForm : Form
- {
- [.....]
- UserContext aContext;
- [.....]
- public void mouseHook_MouseDown(object sender, MouseEventArgs e)
- {
- // Context.Send("asd");
- // AddMouseEvent(
- // "MouseDown",
- //e.Button.ToString(),
- // e.X.ToString(),
- // e.Y.ToString(),
- //""
- //);
- send();
- }
- private void send()
- {
- aContext.Send("123");
- }
- }
Und wenn ich es so probiere nekomm ich : Keine Überladung für die send-Methode nimmt 1 Argument an.
C#-Quellcode
- public void mouseHook_MouseDown(object sender, MouseEventArgs e)
- {
- string mousedata_a;
- // Context.Send("asd");
- // AddMouseEvent(
- // "MouseDown",
- //e.Button.ToString(),
- // e.X.ToString(),
- // e.Y.ToString(),
- //""
- //);
- mousedata_a = "^" + e.X.ToString() + "," + e.Y.ToString();
- send(mousedata_a);
- }
- private void send(string mousedata, UserContext Context)
- {
- Context.Send(mousedata);
- }
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „SykesXablex“ ()