不能使用Windows桌面共享/RDPCOMAPILib的虚拟通道从查看器发送到主机

本文关键字:主机 通道 虚拟 Windows 桌面 共享 RDPCOMAPILib 不能 | 更新日期: 2023-09-27 18:16:54

我正在创建一个windows桌面共享应用程序,除了用于发送聊天消息的虚拟通道外,其他一切都在工作。我可以从主机发送消息到查看器,但反之亦然。查看器正在使用ActiveX RDPViewer。问题是我无法让onchanneldatarereceived事件在主机上触发。我知道有些人以前遇到过这个问题,但是任何帮助都会很感激。

这里有一些片段可能会有所帮助。观众

RDPCOMAPILib.IRDPSRAPIVirtualChannel chan;
chan = rdpViewer.VirtualChannelManager.CreateVirtualChannel(name, RDPCOMAPILib.CHANNEL_PRIORITY.CHANNEL_PRIORITY_HI, 0);

发送i呼叫时

chan.SendData(message, (int)RDPCOMAPILib.RDPENCOMAPI_CONSTANTS.CONST_ATTENDEE_ID_HOST, 0);
主机

chan = rdp.VirtualChannelManager.CreateVirtualChannel(name, RDPCOMAPILib.CHANNEL_PRIORITY.CHANNEL_PRIORITY_HI, 0);
foreach(IRDPSRAPIAttendee attendee in rdp.Attendees)
            this.vc.SetAccess(attendee.Id, RDPCOMAPILib.CHANNEL_ACCESS_ENUM.CHANNEL_ACCESS_ENUM_SENDRECEIVE);

然后我调用这个来发送数据

chan.SendData(message, (int)RDPCOMAPILib.RDPENCOMAPI_CONSTANTS.CONST_ATTENDEE_ID_EVERYONE, 0);

不能使用Windows桌面共享/RDPCOMAPILib的虚拟通道从查看器发送到主机

我使用的技巧很好地满足了我的需求:

//----------------------------------------------------------------------------------------
// On the server/host, create a new session
//----------------------------------------------------------------------------------------
RDPSession session = new RDPSession();
// Then create a virtual channel
IRDPSRAPIVirtualChannel virtualChannel1 = session.VirtualChannelManager.CreateVirtualChannel("foo", CHANNEL_PRIORITY.CHANNEL_PRIORITY_HI, (uint)CHANNEL_FLAGS.CHANNEL_FLAGS_LEGACY);
// Now open the session
session.Open()
// And connect to the received event
session.OnChannelDataReceived += new _IRDPSessionEvents_OnChannelDataReceivedEventHandler(OnChannelDataReceived);
private void OnChannelDataReceived(object pChannel, int lAttendeeId, string bstrData) {
    Debug.WriteLine("Server::OnChannelDataReceived" + bstrData.Trim());
}
//----------------------------------------------------------------------------------------
// On the Client/Viewer side.
//----------------------------------------------------------------------------------------
// AxRDPViewer is the RDPViewer control on your form. Connect using the appropriate criteria.
AxRDPViewer.Connect(strInvitation, strName, strPassword);
// "Bind" the virtual channel by creating one using the same name as the one created on
// the server side.
IRDPSRAPIVirtualChannel virtualChannel1 = RDPViewer.VirtualChannelManager.CreateVirtualChannel("foo", CHANNEL_PRIORITY.CHANNEL_PRIORITY_HI, (uint)CHANNEL_FLAGS.CHANNEL_FLAGS_LEGACY);
// Hook the data received event
RDPViewer.OnChannelDataReceived += new AxRDPCOMAPILib._IRDPSessionEvents_OnChannelDataReceivedEventHandler(RDPViewer_OnChannelDataReceived);
private void RDPViewer_OnChannelDataReceived(object sender, AxRDPCOMAPILib._IRDPSessionEvents_OnChannelDataReceivedEvent e) {
    Debug.WriteLine("Client::OnChannelDataReceived:" + e.bstrData.Trim());
}
//----------------------------------------------------------------------------------------
// Sending data
//----------------------------------------------------------------------------------------
// Now, on both the server and client side, you can send data like this:
virtualChannel1.SendData("yippie!", (int)RDPENCOMAPI_CONSTANTS.CONST_ATTENDEE_ID_EVERYONE, (uint)CHANNEL_FLAGS.CHANNEL_FLAGS_LEGACY);

我希望这对你有帮助。我实际上为此挣扎了一段时间,最后才意识到我在窗体上启动了一个模态对话框,负责挂钩会话事件。所以不要这样做。div;)

使用RDPENCOMAPI_CONSTANTS.CONST_ATTENDEE_ID_EVERYONE不适合我。我解决这个问题的唯一方法是使用SendData迭代会话的与会者。

foreach (IRDPSRAPIAttendee a in _ctx.activeSession.Attendees)
    virtualChannel.SendData(msg, a.Id, Convert.ToUInt32(CHANNEL_FLAGS.CHANNEL_FLAGS_LEGACY));

虽然这解决了主机到查看器的通信,但我仍然无法从连接的查看器接收任何消息,在相同的虚拟通道上注册并使用RDPENCOMAPI_CONSTANTS.CONST_ATTENDEE_ID_HOST常数。

我在服务器端所做的是创建一个新的RDPSession和一个虚拟通道

activeSession = new RDPSession();
virtualChannel = activeSession.VirtualChannelManager.CreateVirtualChannel("myproto", CHANNEL_PRIORITY.CHANNEL_PRIORITY_HI, (uint)CHANNEL_FLAGS.CHANNEL_FLAGS_LEGACY);

OnChannelDataReceived事件创建一个新的处理程序并启动RDP会话。

activeSession.OnChannelDataReceived += new _IRDPSessionEvents_OnChannelDataReceivedEventHandler(OnChannelDataReceived);
activeSession.Open();

事件处理程序如下:

    private void OnChannelDataReceived(object pChannel, int lAttendeeId, string bstrData) {
       switch(bstrData) 
       {
            /* Handle commands here */
            case "mycmd":
                /* Process command and reply using SendData */
                break;
       }
    }

查看器在Windows 10上运行,而服务器在Windows 7上运行,它们都使用由Windows 7 rdpcomen.dll使用tlbimp.exe工具生成的RDPCOMAPI