Search Unity

Creating a custom server

Discussion in 'Multiplayer' started by the_game_maker, Sep 12, 2015.

Thread Status:
Not open for further replies.
  1. the_game_maker

    the_game_maker

    Joined:
    Nov 15, 2014
    Posts:
    65
    So I want to code my own server for players to connect because Photon only gives me 20ccu and Unity Networking is to hard to use. how can I code my own server for players to join
     
  2. Whippets

    Whippets

    Joined:
    Feb 28, 2013
    Posts:
    1,775
    It would be a massive undertaking to start from scratch with your own socket based communication. uNet LLAPI is quite straightforward to use, and there are other options like photon-bolt, and forge.
     
  3. arcady87

    arcady87

    Joined:
    Jul 24, 2013
    Posts:
    25
    @the_game_maker - that's exactly what i already accomplished over here. so, yes, it is highly possible to code your own server from scratch. how did i accomplish it yet? willing to do, researches and lot of patience. the matter of my "server-project" is totally different, however it has not limit if fact of capability (CCU). also, i suggest to look for LevonRavel's project.

    obviously the stability of your server is strongly related to its hardware and typology (VPS or dedicated?). if you are not familiar with this technology and you mean to create (as known as instantiate) your our machine, i can just suggest to look for a professional sysadmin to setup everything (DDOS protection included). if so, prepare to spend many money.

    regards.
    -arcady87
     
    SamyKen995 likes this.
  4. MMOInteractiveRep

    MMOInteractiveRep

    Joined:
    Apr 7, 2015
    Posts:
    88
    Personally I'd go with Lidgren instead of creating own networking solution... If you can't figure out Lidgren then personally you have no business doing anything with networking until you have done a ton more research into it. If you can't figure out these basic systems then you really need to reconsider trying to create your own.
     
  5. Fantastic Worlds Studio

    Fantastic Worlds Studio

    Joined:
    Apr 26, 2015
    Posts:
    48
    You make is sound as if you expect coding your own server will be easy. Its not.
     
    Whippets likes this.
  6. Brent_Farris

    Brent_Farris

    Joined:
    Jul 13, 2012
    Posts:
    881
    @the_game_maker :D Hi there!

    I am personally an advocate for Forge Networking :)

    However! If you would like to do this all on your own it is completely possible to do as well. Some things to consider, if you are doing Webplayer or anything that runs in a web browser then you will need an understanding of TCP sockets. There is an explicit restriction in web browsers that do not prevent UDP, but it requires each request to be authenticated, which makes UDP much slower in this case. TCP will authenticate only once on the initial handshake.

    If you are not doing web, then I would completely recommend looking up UDP. There are a few things you should look out for when doing UDP, it is faster than TCP but you are going to be writing a lot of the TCP(like) logic yourself for anything reliable. In UDP you usually want to blend between reliable packets and unreliable packets. Unreliable packets would be something that you would use for something that is constantly updating (like position or rotation) where it is going to be updated again any moment, so you might as well just not make it reliable. However, there are some things that you want to be reliable, such as remote procedure calls (RPC). Every networking system should support RPC (in one way or another). It is basically a way of calling a method on the remote machines.

    There then are a few things you will need to consider about security. Do you wish for your clients to authenticate or do you wish for your server to authenticate. Often if it is a non-competitive type game and you just want to make a game that will be played among friends where data isn't really important or tracked, then you can do client auth. Otherwise, if you are doing competitive games you will want the server to authenticate. With this choice you will need to look into sending frame identifiers, authenticating the client request and, if doing something like a FPS game, you will want hitbox rewinding so you can roll back and check for events the client is trying to predict. Also you will want client side prediction now that I mention it when it comes to auth server. This is so that the client doesn't have to wait around for the full round trip of its request to see results :).

    C# has some great libraries, however you will not want to use the UDPClient out of the box in C#, you may want to write or modify your own version on top of the socket layer as this will queue up 65k bytes in GC for each UDP message (no bueno). Head on over to Microsoft's documentation to check out the Socket class :D.

    So in reliable UDP packets, you will need some way of identifying each packet being sent, its order and if it is an old one and there is an updated version. Once a client receives a packet that is marked as reliable you will want the client to tell the server that they have received the packet. Of course, the server shouldn't set around all day and wait for the client to respond (because the packet may have dropped). You will want the server to send the packet again to the client after an algorithmic interval (maybe based on ping or any other factor you wish).

    So with networking you also need to come up with your own protocol, basically how the server and clients will communicate, almost like their own language. You will want to compress as much data as possible for this though! Don't waste bytes, especially in this day and age where everyone is getting charged for what they use XD. For UDP that means you will want to come up with your own header setup and even trailer in some cases.

    There are a few more things to go over, but that would make a book out of this post (or book two I should say). :) I think that this basic high level information is enough to really get started on researching the topics and what/where to research.

    Hope this helps! :D

    PS: Here is a video of the final result of all of this :)
     
    kreso, c_hirschi, bit-master and 2 others like this.
  7. DragoDude

    DragoDude

    Joined:
    Dec 3, 2016
    Posts:
    4
    I tried to do that, but I can't figure out how to connect it to Unity.
    Edit:
    Lol I posted this yesterday but it says today.
     
    Last edited: Dec 15, 2018
  8. MrsPiggy

    MrsPiggy

    Joined:
    Jun 13, 2018
    Posts:
    154
    I've recently recommended SmartFoxServer in a couple other threads, after having used it for a little more than a year.It's a solid client and server solution with tons of features, more that I have time to learn. You can write your own server side code in either Java or Javascript and they have client APIs for all major platforms, Unity included.

    As other have suggested coding your own solution is a massive waste of time and requires lots of expertise, which is not acquired overnight. Products like SmartFox, Photon or UNet were built in years by team of experts. The most sensible thing to do is trying them out and see which one can help with your project.

    SmartFoxServer is found at this website --> www.smartfoxserver.com

    Good luck
     
Thread Status:
Not open for further replies.