Reputation: 141
I have this code in a console app:
using System.Text;
using System.Diagnostics;
using System.Net.Sockets;
using System.Net;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
byte[] data = ASCIIEncoding.ASCII.GetBytes("test message");
string IP = "192.168.1.22";
int Port = 2390;
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(IP), Port);
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
socketEventArg.RemoteEndPoint = endPoint;
socketEventArg.SetBuffer(data, 0, data.Length);
client.SendToAsync(socketEventArg);
Debug.WriteLine("sent");
}
}
}
and this code in the Windows Universal App:
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using System.Net;
using System.Net.Sockets;
using System.Diagnostics;
using System.Text;
namespace App6
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
byte[] data = ASCIIEncoding.ASCII.GetBytes("test message");
string IP = "192.168.1.22";
int Port = 2390;
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(IP), Port);
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
socketEventArg.RemoteEndPoint = endPoint;
socketEventArg.SetBuffer(data, 0, data.Length);
client.SendToAsync(socketEventArg);
Debug.WriteLine("sent");
}
}
}
As you can see the content of both is nearly identical.
The IP I set it to send to is a program I'm running on a different computer that I have confirmed works. When I run the console application, it displays the data I sent properly on the program on the other computer, and the console application prints out "sent" on the debug console as it should. The Universal Windows App similarly prints out "sent", however the packet never reaches the other computer.
I checked using WireShark (a network analysis/packet sniffing tool) and it appears that when I use the console application, a UDP packet is sent, but when I use the Universal Windows app, no UDP packets are found.
I am running both programs from Visual Studio 2015 in debug mode, and I can't think of any reason why it wouldn't be working.
Any suggestions or ideas would be helpful!
Upvotes: 0
Views: 310
Reputation: 484
Just a guess - have you added the internetClient capability to your app? https://msdn.microsoft.com/en-us/library/windows/apps/mt280233.aspx
Upvotes: 0