Hey guys, This has most likely been answered already... But I can't find anything that applies at this moment in time and is relevant. So I have started working on a project that I have been taking a break from, and have decided it's time to start working on the networking aspect... Unity's documentation basically says "Do not use UNET as it will be obsolete in upcoming versions", and no replacement is stated... So what should I use for networking? I've looked at external tools but I am not sure what is best for my needs. I will need something that most likely peer 2 peer and will host around 8 players per match / game. I was thinking Photon Cloud (Realtime) would be a good option because I have experience with it, but I'd rather not use a pay to use service if Unity is coming out with a networking solution sometime soon. Has anyone uncovered more information on this subject? Thanks.
For example https://forum.unity.com/threads/ben...dgren-miniudp-hazel-photon-and-others.512507/ Also Connected Games is more appropriate section, for this questions.
Hey, I know you said you don't want to use Photon Cloud because it's paid. However currently they offer a one-time pricing plan. Basically you pay once and have up to 100 Concurrent Users for 60 months(!) The price is quite low, you can check it here: https://www.photonengine.com/en/realtime/pricing Don't forget that there is always a free plan for 20 Concurrent Users which is good for testing. Also while we at it, I wrote a beginners guide for Photon Network, feel free to check it here: https://sharpcoderblog.com/blog/photon-network-beginners-guide It explains how to create a lobby with a Room creation/selection feature and a simple position sync while in the room.
Try this thread. Bunch of discussion on options there. https://forum.unity.com/threads/is-there-a-go-to-solution-for-multiplayer-now.445242/ The short version is there is no current best solution. But there are multiple options to consider.
I'm following your guide to get started as I haven't used Photon in a couple years... There are a bunch of "Photon" projects in the asset store now. Would I want to grab the one listed as "Classic"? I assume this refers to the old one. I need the realtime one that can support multiple rooms / lobbies. Apparently there's PUN 2 now. I'm not sure what that applies to or what is supported and such.
I'm looking into another avenue just in case. I've been working with Photon and I'm not really sure that's what I need. I can write an API and service calls pretty good when it comes to web development, such as... HTTPRequests and responses and whatnot. If I was to set up a custom networked API and have my own server handling users- How would I manage packets being sent back and forth? How do you specifically send a packet and respond to it? Or would someone use an http protocol for this and call the HTTP request from unity and return it from WEBAPI?
You can send data back and forth using sockets. They've been part of the .NET and Mono frameworks since the very beginning and under the hood they're the way every one of these networking APIs functions. https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.socket?view=netframework-3.5 https://www.codeproject.com/Articles/10649/An-Introduction-to-Socket-Programming-in-NET-using
To elaborate more on the idea of creating a custom networking solution, use UDP sockets in C#. With UDP sockets, both ends are a host with an endpoint of IP and port. It is not like TCP where one end is a server and the other is a client. Also, with a UDP socket, you send individual packets instead of streaming the data. You can figure out exactly what you want in each packet, byte by byte, and create your own data serializer/deserializer code. It can be a perfect fit for your game when you build it all yourself instead of trying to use a generic networking solution. If the game is going to be peer to peer, read about STUN. That is a fairly standard method for doing peer to peer gaming networking through client side NATs. https://en.wikipedia.org/wiki/STUN
On the UDP sockets topic, it isn't all that difficult to take the connectionless host nature of UDP sockets and build your own connection oriented client/server functionality on top of it, nor is it really that difficult to want to send arbitrary amounts of data and chop it up on one end then recombine on the other in a reliable manner even with UDP's size limits and lack of built in reliability. If your game needs those kinds of things, they can be implemented. Though if that is most of what you need, then TCP might be a better choice since that comes built in by default.
Thanks for pointing out. The guide indeed applies to the older version of Photon, I have updated the title. Basically 'Photon Unity Networking Free' is now 'Photon Unity Networking Classic - FREE' and 'PUN 2 - FREE' is a newer version, which according to devs, was released as a separated version because it undergone an internal restructuring and the changes were far too great. Their aim with PUN 2 is to improve performance and reduce memory consumption (Garbage Collection). I'll be writing a guide for PUN 2 soon. Should be ready in couple days (I'll post the link here once it's done).
I just wanted to give an update on this thread and say Thank You to everyone for the suggestions. I ended up writing all of the code from scratch, Created a WebAPI project which acts as the master server. (Access to sql server for saving users, and registering list of instance servers) and I created a second project (Console App) that uses system.network.sockets (TCP/UDP). The TCP is working correctly and data can now be sent back and forth (And access the webapi to retrieve user information), the next step is setting up UDP calls for things such as movement. At this point, I will only need a dedicated server in which IIS will host the WebAPI, a few instances of the headless server. (Which may get integrated into unity if I decide to let this be hosted by players). Cheers!
That's pretty much how I did it as well, a basic rest api for authentication which generates a session token, and then the game server is udp and validates the session token when client joins. Basic but it works.