How to get sockets to work between Unity and UWP apps?

2

I am trying to make a game that takes heart rate values from a Microsoft Band. I was trying to check if I can use sockets to get data from an exe file to send it to Unity. But ubnfortunately, UWP apps does not have TcpClient or TcpListener. Unity does not support the other Windows.Networking.Sockets. I would like to know how can I get the two to communicate and send the heart rate values?

Thanks in advance.

P.S if it matters, I am trying to build a UWP 10 app and am using Unity 5.3.4p5.

EDIT: Ok so I managed to get TCPClient and TCPListener to appear in UWP apps by using what was suggested in here: https://github.com/dotnet/corefx/issues/5939

That said to install this: http://www.nuget.org/packages/System.Net.Sockets/4.1.0-beta-23516

Now the problem that is persisting is when I try to intialize a TcpClient. The app auto exits and I am sent to the following code in 'App.g.cs':

        UnhandledException += (sender, e) =>
        {
            if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
        };

I am not sure what to do now. All I am doing is creating one as so:

TcpClient client;
AddressFamily fam;

public MainPage()
    {
        this.InitializeComponent();
        client = new TcpClient(fam);
        ConnectWithBand();
    }

An error finally popped up. It's the following: Unhandled exception at 0x76686D7E (combase.dll) in HRBand.exe: 0xC000027B: An application-internal exception has occurred (parameters: 0x0871B9E0, 0x00000002).

EDIT 2: I gave up on using System.Net.Sockets on UWP so I marked the correct answer for this question. The followup question is here:

How to connect to Unity game server socket from UWP app via sockets?

c#
sockets
unity3d
visual-studio-2015
uwp
asked on Stack Overflow May 17, 2016 by ChaosEmperor93 • edited May 23, 2017 by Community

1 Answer

1

Unity does not support the other Windows.Networking.Sockets

But it does support socket from System.Net.Sockets.

Unity supports TCP socket.

To get socket work with Unity, you have to use Thread or Unity will freeze.

Here is a complete example of a TCP Server in Unity. You can easily port it to TCP client.

answered on Stack Overflow May 17, 2016 by Programmer • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0