Coder Social home page Coder Social logo

windows-appsample-networkhelper's Introduction

page_type languages products description statusNotificationTargets
sample
csharp
windows
windows-uwp
A library and mini-app that show how to use UWP networking APIs to enable network discovery and communication in your games or apps.

NetworkHelper sample library

A sample library and demo mini-app that shows how to use UWP networking APIs to enable network discovery and communication in your games or apps. This sample runs on the Universal Windows Platform (UWP). Specifically, the library provides the ability for:

  • Wi-Fi network discovery and management peer clients over a local Wi-Fi network.
  • Direct communication between discovered devices on the same Wi-Fi network with developer configurable messages.

Running the sample

To run the sample, you need the latest version of Windows 10 installed on your target and development machines. For more information about Windows 10 see the Windows 10 Upgrade page.

To build this sample, you need Visual Studio 2017 and the latest version of the Windows 10 SDK. You can use the free Visual Studio Community Edition to build and run Windows Universal Platform (UWP) apps. To get the latest updates to Windows and the development tools, and to help shape their development, join the Windows Insider Program.

After you have the latest version of Windows 10 and the development tools installed on your machine, you are ready to run the sample in Visual Studio. To do this you need to set the StartUp Project to one of the Demo Apps in the DemoApps folder in Visual Studio. Below are instructions for setting QuizGame as the start up project.

  1. Open the NetworkHelper solution in Visual Studio
  2. In the Solution Explorer, right-click the QuizGame project, then select Set as StartUp Project. StartUp Project Screenshot
  3. You can now deploy to two different devices and Start Debugging (F5) or Start Without Debugging (Ctrl+F5) to try the sample out.

Important Note This sample is supposed to run on two separate devices on the same local network. To get a full experience, deploy this sample to more than one device and make sure they are on the same Wi-Fi network. If you are running into any issues running this sample, make sure that you have started QuizGame on another device and started a new game. If this doesn't work, ensure that your Wi-Fi router or local network system allows UDP multicast packets to be sent and received. Some networks do not allow network discovery by blocking UDP multicast packets.

Demo App

QuizGame is a Universal Windows Platform (UWP) app sample that uses the NetworkHelper library to enable a pub-style trivia game. When running the sample, you are presented with an option to create a new game as a quiz master on your local network or join an existing game and answer questions from the quiz master. Questions appear on the quiz master's screen while players answer the questions on their own devices. A quiz master can advance the game to additional questions and display the scores at the end. Below are some features that QuizGame uses.

  • Simple MVVM (Model, View, ViewModel) coding pattern
  • Simple navigation using code-behind files.
  • NetworkHelper to enable discovery and broadcasting of available games on the local network.
  • NetworkHelper to enable communication between the game and players.

QuizGame game created now waiting for players screenshot QuizGame found a game to join screenshot QuizGame game is in progress screenshot QuizGame question has been answered screenshot

Code at a glance

If you’re just interested in code snippets for certain API and don’t want to browse or run the full sample, check out the following files for examples of some highlighted features:

Below are the details of the NetworkHelper library interface.

  • ICommunicationChannel.cs, ISessionManager.cs, ISessionParticipant.cs, SessionManager.cs, and SessionParticipant.cs:
    • These interfaces represent a generic peer-to-peer helper architecture that provides the framework for implementing various network protocols.
    • The ISessionManager interface and SessionManager abstract class define how a specific protocol can advertise itself to listening participants, manage connected participants, and provide direct communication to connected participants.
    • The ISessionParticipant interface and SessionParticipant abstract class define how a specific protocol can listen for managers, establish a connection to a manager, and communicate directly with managers.
    • The ICommunicationChannel interface defines how message are sent and received between managers and participants.

Below are the details of the TCP/UDP and DNS-SD implementations of the NetworkHelper library interface.

  • TcpCommunicationChannel.cs, UdpManager.cs, UdpParticipant.cs, DnsSdManager.cs, and DnsSdParticipant.cs:
    • These classes are a concrete implementation of the interfaces and abstract classes described above for the TCP/UDP network protocol.
    • The UdpManager class broadcasts UDP messages to listening participants, listens for participant connection requests, and generates TcpCommunicationChannel objects for sending messages to connected participants.
    • The DnsSdManager class registers a DNS-SD instance to listening participants, listens for participant connection requests, and generates TcpCommunicationChannel objects for sending messages to connected participants.
    • The UdpParticipant class listens for UDP messages broadcast by managers, sends UDP connection requests to managers, and generates TcpCommunicationChannel objects for sending messages to managers.
    • The DnsSdParticipant class listens for registered DNS-SD instances, sends UDP connection requests to managers, and generates TcpCommunicationChannel objects for sending messages to managers.
    • The TcpCommunicationChannel class listens for TCP connections and sends TCP messages.
    • You can use the NetworkHelper library as-is in your projects, either directly, or through an adapter to keep it decoupled. (See the Communicator types below for an example of an adapter.)

windows-appsample-networkhelper's People

Contributors

capfei avatar karlerickson avatar microsoft-github-policy-service[bot] avatar mortonfox avatar msatranjr avatar supernova-eng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

windows-appsample-networkhelper's Issues

Exception when creating new game

I cloned this repo, and updated the Windows 10 target version to 2004 (build 19041) when prompted by Visual Studio. Running the app and trying to create a new game results in the following exception

System.Runtime.InteropServices.COMException
  HResult=0x8007271D
  Message=An attempt was made to access a socket in a way forbidden by its access permissions.

An attempt was made to access a socket in a way forbidden by its access permissions.

  Source=System.Private.CoreLib
  StackTrace:
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

  This exception was originally thrown at this call stack:
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)

Here's the call stack

 	System.Private.CoreLib.ni.dll!System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task)	Unknown
 	System.Private.CoreLib.ni.dll!System.Runtime.CompilerServices.TaskAwaiter.GetResult()	Unknown
 	[Waiting on Async Operation, double-click or press enter to view Async Call Stacks]	
>	NetworkHelper.dll!NetworkHelper.UdpManager.StartAdvertisingAsync() Line 99	C#
 	QuizGame.exe!QuizGame.ViewModel.GameViewModel.StartAdvertisingGameAsync(string name) Line 549	C#
 	QuizGame.exe!QuizGame.ViewModel.GameViewModel.get_CreateGameCommand.AnonymousMethod__20_0() Line 190	C#
 	QuizGame.exe!QuizGame.Common.DelegateCommand..ctor.AnonymousMethod__0(object o) Line 160	C#
 	QuizGame.exe!QuizGame.Common.DelegateCommandBase..ctor.AnonymousMethod__0(object arg) Line 235	C#
 	QuizGame.exe!QuizGame.Common.DelegateCommandBase.Execute(object parameter) Line 294	C#
 	QuizGame.exe!QuizGame.Common.DelegateCommandBase.System.Windows.Input.ICommand.Execute(object parameter) Line 280	C#

Does discovery work at all?

I am currently trying to create wrappers around multiple mDNS-SD implementations. Using DeviceInformation.CreateWatcher seems to be the UWP-native way of discovering devices. So I tried adapting DnssdParticipant for my purposes.

The issue I am facing: After calling StartListeningAsync, the watcher's Added and Updated-event never get triggered.

I modified _aqsQueryString in order to discover all services in our network, not only the service type that was defined for the sample game. I went as far as only specifying:

private string _aqsQueryString = $"System.Devices.AepService.ProtocolId:={PROTOCOL_GUID}";

where

private const string PROTOCOL_GUID = "{4526e8c1-8aac-4153-9b16-55e86ada0e54}";

I tried adding additional quotation marks around the GUID, but to no avail.

Either I am doing something completely wrong or something is broken with the functionality surrounding mDNS-SD. Can anybody confirm that the corresponding UWP-APIs should be working fine with following OS/IDE versions?
Win 10 1803 17134.765
VS2019 16.04

Cannot make it work 'Join game'

First of all I apologize might be is a silly thing I am doing wrong. I explain the test environment:

1.- Windows 10 desktop (10.0.586)
2.- Lumia 1320. (10.0.10586.107)
3.- Another Windows 10 desktop (10.0.14295)

I can ping from one to another and remote debugger also works. I have checked the firewall and the apps are allowed. On both 2 and 3 never get's activated the Join button.

Is there any advice to follow about what could be wrong? I do not see any exception and that's my first time trying to understand this matter about networking. Thank you.

Cross platform game

How hard would be to adapt it to work (share code) with Xamarin Forms? Android and iOS can also communicate in local network, but the p2pHelper part that I've seen is dependent on Windows Networking APIs, may be if it turns to a interface, it may be implemented on another platforms...

creating a windows 10 graphical tool (ui) to manage network tcp parameters for gamers

hey there, sorry, im new to github and have had no idea where to place a reqest for this, so i wanted to ask here for advice and help on how to proceed from here.

i wondered wether it would be possible to create an app / tool with a graphical user interface similar to "tcp optimizer" from speedguide.net, so that users can tweak their internet connection for windows 10.

since there were a few changes to tcp paramaters and network subsystems in windows where for example commands and settings have been redesigned or removed, the functionality of tcp optimizer and other tools has become somewhat deprecated and unusable.

i believe giving users full control over all available tcp paramaters for tweaking and tuning would be highly appreciated especially by gamers. default settings provide a wide range for optimizing possibilities.

the tool i have in mind should be able to give full control to all respective commands of the following functions comfortably via graphical ui:

netsh int tcp set
set global
set heuristics
set security
set supplemental

netsh int tcp show
show global
show heuristics
show security
show supplemental

Get-NetAdapter*
Set-NetAdapter*

and so on. the tool should be able to at least run these commands - basically all available tcp parameters - to enable things like:

dma, offloading (ipv4, ipv6, checksum, chimney, ipsec, encapsulated, etc. etc.), rss, rsc, lso, qos, fastopen, ecn, congestion provider, pacingprofile, hystart, cwndrestart, prr, mpp, etc. etc.

commands i am currently using for tweaking are:

Get-NetTCPSetting
Get-NetAdapterAdvancedProperty

Set-NetAdapterRdma -Name "*" -Enabled $True
Set-NetAdapterRsc -Name "*"-IPv4Enabled $True -IPv6Enabled $True
Set-NetAdapterRss -Name "*" -Profile Conservative
Set-NetAdapterIPsecOffload -Name "*" -Enabled $True
Set-NetAdapterChecksumOffload -Name "*" -TcpIPv6Enabled RxTxEnabled
Set-NetAdapterChecksumOffload -Name "*" -IpIPv4Enabled RxTxEnabled -TcpIpv4Enabled RxTxEnabled -UdpIpv4Enabled RxTxEnabled

Enable-NetAdapterChecksumOffload -Name "*"
Enable-NetAdapterIPsecOffload -Name "*"
Enable-NetAdapterRsc -Name "*"
Enable-NetAdapterRss -Name "*"
Enable-NetAdapterQos -Name "*"
Disable-NetAdapterLso -Name "*"
Enable-NetAdapterEncapsulatedPacketTaskOffload -Name "*"
Enable-NetAdapterSriov -Name "*"
Enable-NetAdapterVmq -Name "*"

netsh int tcp set global ecncapability=enabled
netsh int tcp set global rss=enabled
netsh int tcp set global rsc=enabled
netsh int tcp set global dca=enabled
netsh int tcp set global netdma=enabled
netsh int tcp set global fastopen=enabled
netsh int tcp set global fastopenfallback=enabled
netsh int tcp set global prr=enabled
netsh int tcp set global pacingprofile=always
netsh int tcp set global hystart=enabled
netsh int tcp set supplemental internet enablecwndrestart=enabled
netsh int tcp set security mpp=enabled

netsh int tcp set global autotuninglevel=normal
netsh int tcp set supplemental internet congestionprovider=dctcp

there may even be more to find out, but the documentation and usability is somewhat unclear. i am looking for a team of coders to create a tool with ui to enable users / gamers to tweak / tune their internet connection to the maximum.

regards :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.