简体   繁体   English

使用 Windows 桌面共享 API 的 C# 桌面共享

[英]C# desktop sharing using Windows Desktop Sharing API

I have written a simple C# application for desktop sharing using Windows desktop sharing API我已经使用 Windows 桌面共享 API 编写了一个用于桌面共享的简单 C# 应用程序

http://msdn.microsoft.com/en-us/library/bb968809.aspx http://blogs.msdn.com/b/rds/archive/2007/03/08/windows-desktop-sharing-api.aspx http://msdn.microsoft.com/en-us/library/bb968809.aspx http://blogs.msdn.com/b/rds/archive/2007/03/08/windows-desktop-sharing-api.aspx

Most of my application code is based on this Microsoft's blog post http://blogs.msdn.com/b/rds/archive/2007/03/23/writing-a-desktop-sharing-application.aspx我的大部分应用程序代码基于这篇 Microsoft 的博客文章http://blogs.msdn.com/b/rds/archive/2007/03/23/writing-a-desktop-sharing-application.aspx

I have also successfully implemented Reverse Connect http://msdn.microsoft.com/en-us/library/aa373312.aspx我也成功实现了反向连接http://msdn.microsoft.com/en-us/library/aa373312.aspx

My app works great within local network or VPN but I am unable to share desktop to PC's that are on public networks.我的应用程序在本地网络或 VPN 中运行良好,但我无法将桌面共享到公共网络上的 PC。 Invitation generated by my host application looks something like this我的主机应用程序生成的邀请看起来像这样

<E>
  <A KH="3tSA+NXzzvG8ynVkXTh0RxsPCus=" ID="DIC/0Flybjfj3U5lPvy5B2TWwShPrX1oIkpUB0vrB4mZsjZWY7WCfGnvEUjwhvhK"/>
  <C>
    <T ID="1" SID="0">
      <L P="51390" N="fe80::596d:88b0:2ef6:bf13%4"/>
      <L P="51391" N="fe80::103c:155b:b1fc:9854%9"/>
      <L P="51392" N="2001:0:9d38:6abd:103c:155b:b1fc:9854"/>
      <L P="51393" N="2002:c31d:e328:1000:981c:91bc:adbd:6703"/>
      <L P="51394" N="2002:c31d:e328:1000:c878:a88a:f1fb:f25d"/>
      <L P="51395" N="fe80::981c:91bc:adbd:6703%10"/>
      <L P="51396" N="192.168.1.36"/>
    </T>
  </C>
</E>

I have noticed that there is only local IP address in this invitation.我注意到此邀请中只有本地 IP 地址。 Am I doing something wrong here?我在这里做错了吗? Is it even possible to share desktop between PC on public network using Windows Desktop Sharing API?甚至可以使用 Windows 桌面共享 API 在公共网络上的 PC 之间共享桌面吗?

If not, what are my options?如果没有,我有什么选择? Other then setting up VPN?其他然后设置VPN? Thank you谢谢

You could use this:你可以用这个:

// you need to fix the port in order to know the port 
// that  StartReverseConnectListener will use
IRDPSRAPISessionProperties RdpProperties = Viewer.Properties as IRDPSRAPISessionProperties;
RdpProperties["PortId"] = Myport;


 private string AddExIP(string viewerConnectionString)
        {
            TextReader tr = new StringReader(viewerConnectionString);
            XDocument doc = XDocument.Load(tr);

            // get external ip 
            // From http://stackoverflow.com/a/16109156/2573450
            string url = "http://checkip.dyndns.org";
            System.Net.WebRequest req = System.Net.WebRequest.Create(url);
            System.Net.WebResponse resp = req.GetResponse();
            System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
            string response = sr.ReadToEnd().Trim();
            string[] a = response.Split(':');
            string a2 = a[1].Substring(1);
            string[] a3 = a2.Split('<');
            string a4 = a3[0];
            string ExternalIp = a4;

            // Add to connection string
            doc.Element("E").Element("C").Element("T").Add(new XElement("L",
                new XAttribute("P", MyportasString),
                new XAttribute("N", ExternalIp)
                ));
            return doc.ToString();
        }

string viewerConnString = Viewer.StartReverseConnectListener(SessionInvitation, Myname, Mypass);

String NewConnectionString = AddExIP(viewerConnString);

If you are trying to connect to a PC that doesn't have a public IP, you will need to configure your firewall or NAT with some port forwarding rules.如果您尝试连接到没有公共 IP 的 PC,则需要使用某些端口转发规则配置防火墙或 NAT。 Then, use that public IP (eg WAN IP on the router) in your invitation string.然后,在您的邀请字符串中使用该公共 IP(例如路由器上的 WAN IP)。

In the desktop invitation, i see two public ipv6 address.在桌面邀请中,我看到两个公共 ipv6 地址。 One with 2001: its teredo IPv6 address created using ipv4 NAT traversal mechanism & another with 2002: prefix meaning its 6to4 address.一个是 2001:它的 teredo IPv6 地址是使用 ipv4 NAT 遍历机制创建的,另一个是 2002:前缀意味着它的 6to4 地址。 If the other machine also has a public IPv6 address, this invitation should work.如果另一台机器也有公共 IPv6 地址,则此邀请应该有效。 In all windows platform starting from vista, a teredo or 6to4 IPv6 address are initialized by default.从vista开始的所有windows平台,默认都会初始化一个teredo或6to4 IPv6地址。 6to4 & teredo address will not be available if your machine is behind a symmetric NAT or behind proxy.如果您的机器位于对称 NAT 或代理之后,则 6to4 和 teredo 地址将不可用。 Please check if the other machine has ipv6 address.请检查另一台机器是否有ipv6地址。 If it has one, it should work.如果它有一个,它应该可以工作。

You can tunnel the data over an aribitrary transport by implementing IRDPSRAPITransportStream .您可以通过实现IRDPSRAPITransportStream通过任意传输隧道传输数据。 Pass your transport to the sharer using the IRDPSRAPISharingSession2::ConnectUsingTransportStream method, and to the client using IRDPSRAPIViewer::get_Properties with property "SetNetworkStream" .使用IRDPSRAPISharingSession2::ConnectUsingTransportStream方法将您的传输传递给共享器,并使用带有属性"SetNetworkStream" IRDPSRAPIViewer::get_Properties传递给客户端。

A full example available at https://github.com/mgaffigan/RemoteAssistanceSample完整示例可在https://github.com/mgaffigan/RemoteAssistanceSample 获得

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 防止桌面共享特定的c#winforms或检测桌面共享 - Prevent desktop sharing of a particular c# winforms or detect desktop sharing 如何使用Windows桌面共享API共享选择性窗口 - How to share selective windows using Windows Desktop Sharing API c# API 客户端使用桌面应用程序 - c# API client using Desktop application 在移动版和桌面版ASP.NET C#Web应用程序(窗体)之间共享代码 - Sharing Code Between Mobile and desktop version of ASP.NET C# Web Application (Forms) 无法使用带有Windows桌面共享/ RDPCOMAPILib的虚拟频道从Viewer发送到主机 - Can't send from Viewer to Host using Virtual Channels with Windows Desktop Sharing/RDPCOMAPILib 桌面共享和聊天开源 - Desktop Sharing and Chat open source C# windows 桌面应用 - C# windows desktop application 用于Windows桌面C#应用程序的蓝牙4.0(低能耗)API - Bluetooth 4.0 (low energy) API for windows desktop C# application 使用C#使用Winium进行桌面Windows应用程序自动化 - Desktop Windows Application automation using winium using c# 使用C#winforms与Windows中的其他桌面应用程序进行交互 - Interact with other desktop-applications in windows using C# winforms
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM