Alchemy WebSocketServer Send Data

  • C#
  • .NET (FX) 4.0

Es gibt 1 Antwort in diesem Thema. Der letzte Beitrag () ist von SykesXablex.

    Alchemy WebSocketServer Send Data

    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


    C#-Quellcode

    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel;
    4. using System.Data;
    5. using System.Drawing;
    6. using System.Linq;
    7. using System.Text;
    8. using System.Threading.Tasks;
    9. using System.Windows.Forms;
    10. using System.Threading;
    11. using System.Collections.Concurrent;
    12. using Alchemy;
    13. using Alchemy.Classes;
    14. using MouseKeyboardLibrary;
    15. namespace SampleApplication
    16. {
    17. public partial class HookTestForm : Form
    18. {
    19. MouseHook mouseHook = new MouseHook();
    20. public HookTestForm()
    21. {
    22. InitializeComponent();
    23. }
    24. private void TestForm_Load(object sender, EventArgs e)
    25. {
    26. mouseHook.MouseDown += new MouseEventHandler(mouseHook_MouseDown);
    27. mouseHook.Start();
    28. var aServer = new WebSocketServer(8100, System.Net.IPAddress.Any)
    29. {
    30. OnReceive = OnReceive,
    31. OnSend = OnSend,
    32. OnConnected = OnConnect,
    33. OnDisconnect = OnDisconnect,
    34. TimeOut = new TimeSpan(0, 5, 0)
    35. };
    36. aServer.Start();
    37. }
    38. public void mouseHook_MouseDown(object sender, MouseEventArgs e)
    39. {
    40. // Context.Send("asd");
    41. // AddMouseEvent(
    42. // "MouseDown",
    43. //e.Button.ToString(),
    44. // e.X.ToString(),
    45. // e.Y.ToString(),
    46. //""
    47. //);
    48. }
    49. void AddMouseEvent(string eventType, string button, string x, string y, string delta)
    50. {
    51. listView1.Items.Insert(0,
    52. new ListViewItem(
    53. new string[]{
    54. eventType,
    55. button,
    56. x,
    57. y,
    58. delta
    59. }));
    60. }
    61. public static void OnConnect(UserContext aContext)
    62. {
    63. MessageBox.Show("Client Connected From : " + aContext.ClientAddress.ToString());
    64. // Create a new Connection Object to save client context information
    65. // var conn = new Connection { Context = aContext };
    66. // Add a connection Object to thread-safe collection
    67. //OnlineConnections.TryAdd(aContext.ClientAddress.ToString(), conn);
    68. }
    69. public static void OnReceive(UserContext aContext)
    70. {
    71. try
    72. {
    73. MessageBox.Show("Data Received From [" + aContext.ClientAddress.ToString() + "] - " + aContext.DataFrame.ToString());
    74. }
    75. catch (Exception ex)
    76. {
    77. Console.WriteLine(ex.Message.ToString());
    78. }
    79. }
    80. public static void OnSend(UserContext aContext)
    81. {
    82. // MessageBox.Show("Data Sent To : " + aContext.ClientAddress.ToString());
    83. }
    84. public static void OnDisconnect(UserContext aContext)
    85. {
    86. // -------------- "Client Disconnected : " + aContext.ClientAddress.ToString();
    87. // Remove the connection Object from the thread-safe collection
    88. // Connection conn;
    89. //OnlineConnections.TryRemove(aContext.ClientAddress.ToString(),out conn);
    90. // Dispose timer to stop sending messages to the client.
    91. //conn.timer.Dispose();
    92. }
    93. private void TestForm_FormClosed(object sender, FormClosedEventArgs e)
    94. {
    95. // Not necessary anymore, will stop when application exits
    96. //mouseHook.Stop();
    97. //keyboardHook.Stop();
    98. }
    99. }
    100. public class Connection
    101. {
    102. public System.Threading.Timer timer;
    103. public UserContext Context { get; set; }
    104. public Connection()
    105. {
    106. this.timer = new System.Threading.Timer(this.TimerCallback, null, 0, 1000);
    107. }
    108. private void TimerCallback(object state)
    109. {
    110. try
    111. {
    112. // Sending Data to the Client
    113. // Context.Send("[" + Context.ClientAddress.ToString() + "] " + System.DateTime.Now.ToString());
    114. }
    115. catch (Exception ex)
    116. {
    117. Console.WriteLine(ex.Message);
    118. }
    119. }
    120. }
    121. }


    Wenn ich es mit dem unten stehenden Code versuche get das Programm einfach aus.

    C#-Quellcode

    1. public partial class HookTestForm : Form
    2. {
    3. [.....]
    4. UserContext aContext;
    5. [.....]
    6. public void mouseHook_MouseDown(object sender, MouseEventArgs e)
    7. {
    8. // Context.Send("asd");
    9. // AddMouseEvent(
    10. // "MouseDown",
    11. //e.Button.ToString(),
    12. // e.X.ToString(),
    13. // e.Y.ToString(),
    14. //""
    15. //);
    16. send();
    17. }
    18. private void send()
    19. {
    20. aContext.Send("123");
    21. }
    22. }


    Und wenn ich es so probiere nekomm ich : Keine Überladung für die send-Methode nimmt 1 Argument an.

    C#-Quellcode

    1. public void mouseHook_MouseDown(object sender, MouseEventArgs e)
    2. {
    3. string mousedata_a;
    4. // Context.Send("asd");
    5. // AddMouseEvent(
    6. // "MouseDown",
    7. //e.Button.ToString(),
    8. // e.X.ToString(),
    9. // e.Y.ToString(),
    10. //""
    11. //);
    12. mousedata_a = "^" + e.X.ToString() + "," + e.Y.ToString();
    13. send(mousedata_a);
    14. }
    15. private void send(string mousedata, UserContext Context)
    16. {
    17. Context.Send(mousedata);
    18. }

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „SykesXablex“ ()