带有 Uno 平台应用程序的 Socket Err 10013
Socket Err 10013 with Uno Platform apps
我的网络和笔记本电脑中都有 Beamer。
我制作了一个控制台应用程序来通过 TCP/IP 协议打开投影仪 on/off,它工作正常。
现在我想要一个花哨的 Uno GUI,背后有相同的代码,但令人惊讶的是现在我得到了一个套接字异常:
10013: An attempt was made to access a socket in a way forbidden by its access permissions
我已经连续 3 天用谷歌搜索并尝试了很多东西,包括
- 防火墙settings/turn关闭
- 权限组编辑
- 奇怪的代码我实在无法测试。
我正在使用 Visual Studio 2019
如果有人需要,请输入以下代码:
如果有人能帮助我,我将不胜感激。
这里是代码对比:
控制台代码:
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace Test
{
class Programm
{
static void Main(String[] args)
{
Console.WriteLine("START Enter");
Console.ReadLine();
const int Port = 7142;
const string IPv4 = "192.168.10.70";
IPAddress ipo = IPAddress.Parse(IPv4);
IPEndPoint ipEo = new IPEndPoint(ipo, Port);
var endpoint = new IPEndPoint(ipo, Port);
var socket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
Console.WriteLine("Verbindung wird Aufgebaut mit");
Console.WriteLine("Adresse: " + IPv4);
Console.WriteLine("Port: " + Port);
try
{
socket.Connect(endpoint);
}
catch(SocketException se)
{
Console.WriteLine("Verbindung Gescheitert");
Console.WriteLine(se.ErrorCode + ": " + se.Message);
Console.ReadLine();
}
Console.WriteLine("Verbindung hergestellt");
Console.WriteLine("Befehl senden?");
Console.ReadLine();
Console.WriteLine("Befehl wird gesendet");
var networkstream = new NetworkStream(socket, true);
var msg = "\x02\x01\x00\x00\x00\x03";
var buffer = System.Text.Encoding.UTF8.GetBytes(msg);
foreach (int i in buffer)
{
Console.Write("{0} ", i);
}
networkstream.Write(buffer, 0, buffer.Length);
var response = new byte[1024];
var bytesRead = networkstream.Read(response, 0, response.Length);
var responseStr = System.Text.Encoding.UTF8.GetString(response);
Console.WriteLine("");
Console.WriteLine("Empfangen wurde:");
foreach (int i in response)
{
Console.Write("{0} ", i);
}
Console.ReadLine();
}
}
}
现在 UNO 应用代码:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Text;
using System.Net.Sockets;
using System.Net;
namespace Test
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
public void Ein_Click(object sender, RoutedEventArgs e)
{
const int Port = 7142;
const string IPv4 = "192.168.10.70";
IPAddress ipo = IPAddress.Parse(IPv4);
IPEndPoint ipEo = new IPEndPoint(ipo, Port);
var endpoint = new IPEndPoint(ipo, Port);
var socket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
try
{
socket.Connect(endpoint);
System.Diagnostics.Debug.WriteLine("Verbindung Wurde aufgebaut");
var networkstream = new NetworkStream(socket, true);
var msg = "\x02\x00\x00\x00\x00\x02";
var buffer = System.Text.Encoding.UTF8.GetBytes(msg);
networkstream.Write(buffer, 0, buffer.Length);
socket.Disconnect(true);
}
catch (SocketException se)
{
Testblock1.Text = se.ErrorCode + ": " + se.Message;
System.Diagnostics.Debug.WriteLine("Verbindung Gescheitert");
System.Diagnostics.Debug.WriteLine(se.ErrorCode + ": " + se.Message);
}
}
您似乎以本地网络 IP 地址为目标,这需要在您的 UWP 应用项目中声明特殊权限。在 UWP 项目中应该有一个 Package.appxmanifest
文件。双击它和 select Capabilities 选项卡。然后在下面的列表中选中 Private Networks (Client & Server).
旁边的框
我的网络和笔记本电脑中都有 Beamer。
我制作了一个控制台应用程序来通过 TCP/IP 协议打开投影仪 on/off,它工作正常。
现在我想要一个花哨的 Uno GUI,背后有相同的代码,但令人惊讶的是现在我得到了一个套接字异常:
10013: An attempt was made to access a socket in a way forbidden by its access permissions
我已经连续 3 天用谷歌搜索并尝试了很多东西,包括
- 防火墙settings/turn关闭
- 权限组编辑
- 奇怪的代码我实在无法测试。 我正在使用 Visual Studio 2019 如果有人需要,请输入以下代码:
如果有人能帮助我,我将不胜感激。
这里是代码对比:
控制台代码:
using System; using System.Net; using System.Net.Sockets; using System.Text; namespace Test { class Programm { static void Main(String[] args) { Console.WriteLine("START Enter"); Console.ReadLine(); const int Port = 7142; const string IPv4 = "192.168.10.70"; IPAddress ipo = IPAddress.Parse(IPv4); IPEndPoint ipEo = new IPEndPoint(ipo, Port); var endpoint = new IPEndPoint(ipo, Port); var socket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); Console.WriteLine("Verbindung wird Aufgebaut mit"); Console.WriteLine("Adresse: " + IPv4); Console.WriteLine("Port: " + Port); try { socket.Connect(endpoint); } catch(SocketException se) { Console.WriteLine("Verbindung Gescheitert"); Console.WriteLine(se.ErrorCode + ": " + se.Message); Console.ReadLine(); } Console.WriteLine("Verbindung hergestellt"); Console.WriteLine("Befehl senden?"); Console.ReadLine(); Console.WriteLine("Befehl wird gesendet"); var networkstream = new NetworkStream(socket, true); var msg = "\x02\x01\x00\x00\x00\x03"; var buffer = System.Text.Encoding.UTF8.GetBytes(msg); foreach (int i in buffer) { Console.Write("{0} ", i); } networkstream.Write(buffer, 0, buffer.Length); var response = new byte[1024]; var bytesRead = networkstream.Read(response, 0, response.Length); var responseStr = System.Text.Encoding.UTF8.GetString(response); Console.WriteLine(""); Console.WriteLine("Empfangen wurde:"); foreach (int i in response) { Console.Write("{0} ", i); } Console.ReadLine(); } } }
现在 UNO 应用代码:
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using Windows.Foundation; using Windows.Foundation.Collections; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls.Primitives; using Windows.UI.Xaml.Data; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; using System.Text; using System.Net.Sockets; using System.Net; namespace Test { public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); } public void Ein_Click(object sender, RoutedEventArgs e) { const int Port = 7142; const string IPv4 = "192.168.10.70"; IPAddress ipo = IPAddress.Parse(IPv4); IPEndPoint ipEo = new IPEndPoint(ipo, Port); var endpoint = new IPEndPoint(ipo, Port); var socket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); try { socket.Connect(endpoint); System.Diagnostics.Debug.WriteLine("Verbindung Wurde aufgebaut"); var networkstream = new NetworkStream(socket, true); var msg = "\x02\x00\x00\x00\x00\x02"; var buffer = System.Text.Encoding.UTF8.GetBytes(msg); networkstream.Write(buffer, 0, buffer.Length); socket.Disconnect(true); } catch (SocketException se) { Testblock1.Text = se.ErrorCode + ": " + se.Message; System.Diagnostics.Debug.WriteLine("Verbindung Gescheitert"); System.Diagnostics.Debug.WriteLine(se.ErrorCode + ": " + se.Message); } }
您似乎以本地网络 IP 地址为目标,这需要在您的 UWP 应用项目中声明特殊权限。在 UWP 项目中应该有一个 Package.appxmanifest
文件。双击它和 select Capabilities 选项卡。然后在下面的列表中选中 Private Networks (Client & Server).