Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions Others/C# UDP Client
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Popups;
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;


namespace UWPTestClientUDP
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}

private void btn_Click(object sender, RoutedEventArgs e)
{

errorblk.Text = "";

MessageDialog dialog = new MessageDialog("");

try
{
if (AddressBox.Text == "")
dialog.Content = "Insert IP Address";

if(AddressBox.Text != "")
{
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

var addressText = AddressBox.Text.Replace(',', '.');
AddressBox.Text = addressText;

IPAddress broadcast = IPAddress.Parse(addressText);

byte[] sendbuf = Encoding.ASCII.GetBytes(txtblk.Text);
IPEndPoint ep = new IPEndPoint(broadcast, 11000);

s.SendTo(sendbuf, ep);

errorblk.Foreground = new SolidColorBrush(Colors.Green);
errorblk.Text = "Message Sent";
}
}
catch (Exception ex)
{
errorblk.Foreground = new SolidColorBrush(Colors.Red);

errorblk.Text = ex.ToString();
}
}
}
}