0

I have created a Unity application that uses System.Net.Sockets for TCP communication with a separate server computer. This application works flawlessly in the editor, and when built for Android or PC. But when I tried to create an iOS build (on a MacBook) the app loads correctly, but no network communication is made.

Next I created a developer build, but no errors or warnings appeared during runtime, it just didn't connect to the server. I made sure to double check that they were both on the same network, and that the ports are set correctly.

I am currently debugging and looking through documentation, but I haven't seen anything stating that System.Net.Sockets is incompatible with iOS. Once the following questions are answered I can upload code snippets / ask a new question about the specific code.

Does Unity support System.Net.Sockets for iOS? Is there something unique that needs to be done when building a networked project for iOS?

Thank you for your time and assistance!

NCarlson
  • 330
  • 2
  • 13
  • The questions is really not a good fit for SO. You may first find out how System.Net.Sockets is implemented on iOS, examining the auto generated C++ sources or the Mono implementation of .NET to get more clues about it. It probably resolves down to Darwin. Also, you should provide any errors or console output. – CouchDeveloper Jan 14 '21 at 15:57
  • 1
    @NCarlson just briefly ... in practice you all-but-have-to simply use this websocket library in Unity .. https://github.com/Marfusios/websocket-client (there was previously another one that was popular, but it has fallen apart with time). It is really an immense amount of work to use Net Sockets from scratch. (It';s one of those things that is incredibly harder than it appears at first sight. :/ ) – Fattie Jan 14 '21 at 18:56
  • 1
    (example, https://stackoverflow.com/q/63712116/294884 ) – Fattie Jan 14 '21 at 18:57
  • 1
    Also @NCarlson be aware it is really , really tricky to use messaging (which is continuous) in a frame-based game engine. If you really are going to try YOURSELF tyo write from scratch with net sockets, here: https://gamedev.stackexchange.com/a/169413/86883 – Fattie Jan 14 '21 at 19:19
  • I basically just want a really simple way to send data from the server (a program on an ubuntu machine) to the client (unity application) to display. The code I have is working for PC and android, but it doesnt work on iOS - or hololens (windows with MRTK) – NCarlson Jan 14 '21 at 19:31
  • @Fattie, do you know why / what specifically makes net sockets incompatible on the iOS / other target versions? – NCarlson Jan 14 '21 at 19:33
  • As I say in my answer, *it should work* but it's an age-old puzzle, and I haven't tried it for awhile - so I hope you get someone with more info! FTR on the ubuntu server side we use Node.js and the amazing library https://github.com/websockets/ws – Fattie Jan 14 '21 at 19:37
  • **very basic** .. sure you've turned on full .Net in unity? (not the subset) – Fattie Jan 14 '21 at 19:39
  • - I tried that, no change. I am looking into using the websockets client you mentioned. This question got closed and downvoted because they want non-existent debug messages. I have yet to get any error codes / messages, and the point of the question was that it worked on PC and android, but not on iOS : Why? Thanks Fattie! – NCarlson Jan 15 '21 at 15:51
  • 1
    a great tip is hop on the forum for the excellent BestHTTP/2 package (and/or other similar asset store libraries). you can go right ahead and ask the question on there. this is often the cleverest way to find information. to make an example, the guy who created the usual camera asset for unity, literally knows more about "camera in unity" issues than any other living human! heh! its often the best/only place to ask such questions – Fattie Jan 15 '21 at 16:36

1 Answers1

1

A quick pathetic answer:

  • Whether or not System.Net.Sockets in Unity works in iOS / Android builds is one of the great mysteries of the ages, and the answer changes every few months :/

  • I am almost certain it is currently possible ...

For example, notice this popular library https://assetstore.unity.com/packages/tools/network/best-http-2-155981 which works perfectly with ios/droid, and indeed is ultimately just .Net underneath.

(A worthwhile tip is, get on the forum of that library and pose your problem...)

Problems ...

Fattie
  • 27,874
  • 70
  • 431
  • 719