C#socket.io不听发射事件

我试图编写一个程序,让我通过一个控制面板通过websocket(在Raspberry Pi上)发送消息来控制计算机的音量。

我已经写了控制面板和Node.JS服务器,但是,我有控制台应用程序的问题(加载到我想要控制的PC上)根本不在消息或发出,尽pipe连接到服务器好(我知道这是我的服务器login到它的控制台,用户连接)。

我是C#的新手(截至昨天),所以我对这门语言的了解让我很难find这个问题。 有什么build议么?

编辑 – .On方法根本不运行。 我试图写入控制台而不是改变音量,它不工作。

控制台应用程序:

 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.InteropServices; using AudioSwitcher.AudioApi.CoreAudio; using Quobject.SocketIoClientDotNet.Client; namespace SoundControlV1 { class Program { //Hide Console Code. [DllImport("kernel32.dll")] static extern IntPtr GetConsoleWindow(); [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); const int SW_HIDE = 0; const int SW_SHOW = 5; static void Main(string[] args) { //Launch Message Console.WriteLine("Sound Control V1 Launching..."); //Init Socket. var socket = IO.Socket("http://ip:3000"); CoreAudioDevice defaultPlaybackDevice = new CoreAudioController().DefaultPlaybackDevice; //Sleep. System.Threading.Thread.Sleep(2000); //Hide Console. ShowWindow(GetConsoleWindow(), SW_HIDE); Console.WriteLine("Test"); //Socket Actions. socket.On("SOUND_UP", (data) => { Console.Write("Test"); defaultPlaybackDevice.Volume = defaultPlaybackDevice.Volume + 10; }); socket.On("SOUND_DOWN", (data) => { defaultPlaybackDevice.Volume = defaultPlaybackDevice.Volume - 10; }); //Prevent app from closing. Console.ReadKey(); } } } 

服务器代码:

  var server = require('http').createServer(); var io = require('socket.io')(server); io.on('connection', function(client){ //General Functions. console.log('A User has connected to the Socket!'); client.on('disconnect', function(){ console.log('A User has disconnected from the Socket!'); }); //Message Test client.on("message", function(data){ console.log(data); client.send(data); }); //Sound Control Functions. client.on("SOUND_UP", function(data){ console.log("SOUND_UP"); client.emit("SOUND_UP"); }); client.on("SOUND_DOWN", function(data){ console.log("SOUND_DOWN"); client.emit("SOUND_DOWN"); }); }); server.listen(3000); 

修复! 🙂

在做最后的testing之前,我无法准确地确定问题所在。

首先,我更新了socket.io(使用的是旧的项目,我曾经作为服务器)。

其次,我改变了服务器使用io.emit("SOUND_UP")而不是client.emit...