Unity Socket



  1. Unity Socket Sets
  2. Unity Socket
  3. Unity Socket Io Client

One of the first things I had to do, was figuring out how to connect to an external server via Unity client using a TCP/IP socket. It took a lot of searching to find help on this issue but I did find it eventually. I’ve added links to my files here so you can view/use them.

So to get your Unity application to connect to an external server via TCP/IP socket, you will need the following:

Unity socket lib

46 thoughts on “ Unity3D and TCP/IP Socket Connections ” fodakahn says: December 9, 2014 at 7:28 pm. By harnessing deflection of the Carbon-X® Active Heel, the Unity vacuum pump draws air out of the socket and elevates vacuum up to 22inHG within a few steps. Adding only 130g to the overall weight of the foot module, the Unity vacuum pump is a light weight solution. Directly attached to. You can declare socket and other networkstream objects as public then initialize them in a thread function. Unity does not work well with while loops in Threads and may freeze sometimes, but you can fix that by adding System.Threading.Thread.Sleep (1); in your while loop where you are reading or waiting for data to arrive from socket.

Unity Socket Sets

TCPConnection.cs – the connection handler, server communications
socketScript.cs – the script attached to one of the GameObjects in Unity (I used the Main Camera). We will use this script to attach a copy of TCPConnection.cs to the Camera as well.

Unity Socket

I’ve added comments to the important things, hopefully they make sense.
If you want to use javascript instead of C# for your socketScript and application in general, remember to move the TCPConnection.cs into the /Assets/Standard Assets folder (just create it if it doesn’t exist) for it to work. In my case (since I used C#, I just put them both in the /Assets/Scripts folder).

I wrote my own very basic C++ windows socket server to test this. When interacting with server, make sure that your server returns the newline command after every response, otherwise your unity client will be left to hang (until the server disconnects). For our server we had to use n but it depends on what type of server you are running.

Socket

If you want to have multiple connections (like for most games, you’ll have the login server and the game/world server), you just got to add another instance of TCPConnection.cs to your socketScript.

Unity Socket Io Client

Socket

Moving notice:
I wasn’t gonna bring over both posts separately, so this already includes the updates for multiple messages at once and using the split method to separate them. Also I’m now hosting these files here on this actual server instead of my synamicdsolutions URL.