0

我正在创建一个 Windows 桌面共享应用程序,除了用于发送聊天消息的虚拟通道外,一切正常。我可以将消息从主机发送到查看器,但反之则不行。查看器正在使用 ActiveX RDPViewer。问题是我无法在主机上触发 OnChannelDataRecieved 事件。我知道有些人以前遇到过这个问题,但我们将不胜感激。

这里有一些可能会有所帮助的片段。查看器

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

然后在发送时我打电话

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);
4

2 回答 2

2

这是我使用的适合我需要的技术:

//----------------------------------------------------------------------------------------
// 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);

我希望这会有所帮助。我实际上为此苦苦挣扎了一段时间,最后才意识到我正在我的表单上启动一个模式对话框,该对话框负责挂钩会话事件。所以不要那样做。;)

于 2012-03-14T19:09:56.853 回答
1

使用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 7rdpcomen.dll使用tlbimp.exe工具生成的 RDPCOMAPI。

于 2018-09-18T15:27:20.587 回答