我正在创建一个Windows桌面共享应用程序,除了用于发送聊天消息的虚拟通道外,其他一切都正常工作。我可以从主机向Viewer发送消息,反之亦然。 Viewer正在使用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);
答案 0 :(得分: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);
我希望有所帮助。我实际上已经挣扎了一段时间,结果却发现我在我的表单上启动了一个负责挂钩会话事件的模式对话框。所以不要这样做。 ;)
答案 1 :(得分: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;
}
}
Viewer在Windows 10上运行,而服务器在Windows 7上运行,它们都使用从Windows 7 rdpcomen.dll
使用tlbimp.exe
工具生成的RDPCOMAPI。