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?

Community
  • 1
  • 1
ChaosEmperor93
  • 117
  • 3
  • 12

1 Answers1

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.

Community
  • 1
  • 1
Programmer
  • 121,791
  • 22
  • 236
  • 328
  • Interesting. Will both be still able to connect even though one is using System.Net.Sockets and the other is using Windows.Networking.Sockets? Sorry, this is quite new for me – ChaosEmperor93 May 18 '16 at 00:41
  • Socket is socket. A TCP network code written in Java or C++ will be able to communcate with one in TCP network in C#. As long as Windows.Networking.Sockets uses a TCP socket, you can communicate with it using another TCP socket library. It will work. – Programmer May 18 '16 at 01:26
  • Alright. Will test it out and let you know how it goes. Thanks! – ChaosEmperor93 May 18 '16 at 01:54
  • @ChaosEmperor93 You are welcome! I expect it to work. If that is the case don't forgot to tick this answer. – Programmer May 18 '16 at 01:57
  • can you have a look at my question again? I added a new problem. Also, I didn't manage to find how to do the Client side of the link you sent me but I stumbled upon how to use TcpClient in UWP apps – ChaosEmperor93 May 18 '16 at 19:29
  • The reason I went with TcpClient instead of using your link is because I already have a working tcp sever on Unity. I just need to get the TcpClient to work in VS – ChaosEmperor93 May 18 '16 at 19:47
  • @ChaosEmperor93 **Unity does not support the other Windows.Networking.Sockets** I thought that the original question is how to do this in unity because you think that unity does not support Windows socket. Now you are asking how to do it in VS. I am confused. – Programmer May 18 '16 at 20:23
  • I was not specific to any platform to be honest. I wanted to know which I could use in either and how. At the moment I have a working tcp server in unity but the client in VS doesn't seem to work at all. Sorry for the confusion – ChaosEmperor93 May 18 '16 at 20:28
  • Due to the confusion I will mark your question as correct but please come go to the question here for the new problem: http://stackoverflow.com/questions/37309851/how-to-connect-to-unity-game-server-socket-from-uwp-app-via-sockets – ChaosEmperor93 May 18 '16 at 20:49