Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity client-server app: any tips?

Discussion in 'Multiplayer' started by Simone, Sep 16, 2008.

  1. Simone

    Simone

    Joined:
    May 15, 2008
    Posts:
    5
    Hello everyone,
    i've been lurking for a while and now it's time for me to post some questions i'm thinking about.


    I'm working for a small italian company who is developing a small client-server application in which users will be able to chat and use/watch their own multimedia contents, like images, audios and videos.

    All this stuff will be stored on a central server, and uploaded through a web page.


    Now i'm thinking/shaping the networking part of the code which basicly have to do a user/pass login, keep up a small chat system, retrieve the list of available contents for that user and, when requested, retrieve the content.


    Now teh questions:
    - login security: can i use https with wwwform? Can RPC calls use any sort of security algorithm (like sha1)? Between wwwform and rpcs, which way is better/more secure for this task?

    - I'd like to download contents and lists directly through www() calls, thus bypassing Game Server, to speed up the whole thing. Is this safe?

    - Game Server is going to be a sort of relay (receive from one, sends to all) for player's positions and chat messages. Do i need to write my own ultra-optimized-raknet-based game server or can i use something built in unity? Where do i find info on how ot make the raknet-based one? What is (more or less) the cap to the number of users in each way?

    - I'd like to use javascript to build all this procedures. Am i creating a bottleneck because of js interpretation? Would c# be way better?



    Thanks, for now.. ;)

    Simone
     
  2. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Hi Simone,

    and welcome ;-)

    The network communication built into Unity (for using RPC calls) does support encryption, see:

    Network.InitializeSecurity

    Concerning HTTPS and WWWform: I think I've read that some people had trouble with this, but I haven't tried it myself. Could have been just an invalid certificate or something like that. Some pointers that might shed light on this:

    http://forum.unity3d.com/viewtopic.php?t=13685
    http://forum.unity3d.com/viewtopic.php?t=10069

    I guess this depends on whether the WWW class does support HTTPS or not. If it does, it should be safe, if not ... you might have to implement your own security layer to make it safe. Or talk to UT to see if there's a way to make HTTPS work with the WWW class (if it really doesn't support this, yet, this is something I would consider a bug ;-) ).

    From the "networking perspective" (i.e. stability), it should be safe. In other words: WWW access should not interfere with Unity networking.

    From your description, it seems that the application is simple enough that you should be able to build a "Unity server". The only limitation I currently see with that approach is that while there seems to be a headless server mode on Mac, there's no such thing (yet) for Windows, and Windows server hosting is usually cheaper and easier than Mac server hosting.

    Since there's no heavy game logic involved, you should be able to host many more users than for any typical multiplayer game, but I guess the only way to get reliable numbers is creating a simple testing simulation and testing as many users as you feel you need.

    You could either implement your own position synchronization via RPCs, or use the NetworkView synchronization. In both cases, it should be possible to create some sort of simulation that will spit out somewhat reliable numbers.

    With my current game (Traces of Illumination, previously TRaceON), I can simulate around 10 players on a single machine (Mac Pro) with the actual game clients ("AI controlled") - but that's a "real game", so I guess with something much simpler (and more designed for simulating heavy loads of users), you could simulate many more users on a single machine, so you might be able to simulate intense numbers of users with just a couple of machines.


    One thing to keep in mind if you're creating a Unity server: Make sure everything that's not absolutely needed is switched off on the server. The nice thing about this approach is that you have just a single project which ends up being both client and server (with conditional compilation, where needed, if needed). But obviously, you don't want to render everything on a server that no one looks at ;-)

    Oh oh, JavaScript vs C# ;-)

    But seriously: If JavaScript is your preferred language, you should go with that. In Unity, both C# and JavaScript are compiled into bytecode and then run in a virtual machine - so at runtime, there should not be any performance differences, except for when you use JavaScript features that consume time (dynamic typing). There's something like @pragma strict to prevent usage of such features (but I'm not a JavaScript guy, so this is just from faint memory ;-) ).

    Sunny regards,
    Jashan
     
  3. Thomas-Lund

    Thomas-Lund

    Joined:
    Jan 18, 2008
    Posts:
    465
    There is also the option of using Smartfox Server together with the .NET client API (written by yours truly).

    While not build into Unity out-of-the-box, it does lobby, chat and easy sending of objects (with e.g. player positions) to other clients.

    Check it out here:

    http://www.smartfoxserver.com/

    Comes with a small basic Unity lobby system as a demo.
     
  4. Simone

    Simone

    Joined:
    May 15, 2008
    Posts:
    5
    Thank you!


    Thanks! Seems to be nicely working... still have to try to dump some traffic to see what's going on.


    Maybe i have to look better for it.. havent found anything on this yet.



    Yes you got it, the server app is really simple. What do you mean with "headless server mode"? Is it related to the "-batchmode" flag?

    Had no time to test it yet, i'm still writing some try-test-and-debug code directly into the OnGUI() for now... ! (yes only for now!!) ;)


    Oh noes! I dont wanna wake up teh flamers! It was just an innocent question! 8)

    Ok. I'll try to stick to javascript then.


    Sunny thanks!!
     
  5. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Yes. It somewhere says that this is supported now in pro (this posting, to be exact), but I've just tried that with my game server, on my Mac, using the approach as described in this posting, and while I do get a message "Starting Server", I can't find the process, and I also don't get any logging (which I'm doing via log4net, so this *should* go into the relevant file).

    When I start the server "normally", i.e. with GUI, everything's working just fine.

    So, I really wish there was some documentation on this -batchmode feature ;-)

    Sunny regards,
    Jashan