Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Dual Unity for network testing?

Discussion in 'Editor & General Support' started by elias723, Jul 18, 2006.

  1. elias723

    elias723

    Joined:
    Feb 10, 2006
    Posts:
    178
    Hey everyone. I'm trying my hand at making a networked scene, but I'm running into trouble other than the usual type. I have a server and a client scene, and they should be talking to each other, but I don't know how to test them if they are running in the same Unity window. I can't run them simultaneously unless I build them. Is there some way I could run both of them inside Unity simultaneously?

    Also, if I have just my server scene running, how would it be able to connect to anything? I'm basically just using the client and server scripts from the NetworkedCursor example, and my server message receiver says it "Did connect", without anything to connect to. Its a little weird.

    EDIT:

    Now while I'm running my server receiver it tells me that I have "too many open files". Is this interference from some other source? I put in my own IP address for the client.cs-like scripts so I would be able to control that, but it didn't work. Also, the error log no longer has the red X marks next to these exceptions (weird).

    Also, now Unity will crash after telling me I moved a project file while it was playing the server scene. Maybe I'm just being hacked...
     
  2. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    Are you running two instances of Unity on the same machine? I think this may not be a very good idea.

    You might be able to get away with running it as two seperate users using the user switching in OSX to have both logged in at the same time.

    If that fails, you can build either the server or client part as a Unity Player and run it as a standalone.
     
  3. klindeman

    klindeman

    Joined:
    Jun 13, 2005
    Posts:
    295
    I did this quite a few times without hassle during the 1.5 beta cycle. I would be running a 1.5 beta, and 1.2.2. Only problem I had was that things kept wanting to open in 1.5, since it was the latest version.
     
  4. elias723

    elias723

    Joined:
    Feb 10, 2006
    Posts:
    178
    Oh - thanks - it didn't occur to me that I could build the client as a standalone and just have it talk with the server in the Unity window. That solves that problem.

    Now, I'm having trouble with the data sending. The client sends it to the server, and the server picks it up, but its not quick and it's not pretty. I made the packets smaller by using integers from -100 to 100 instead of floats (by converting on both ends). The only things it is sending now are 4 ints, but it runs very slowly compared to the "NetworkCursor" sample project, which is very quick. The Network Cursor example also is sending more data than I am - a string, two floats, and an integer. Anybody have any ideas why?
     
  5. elias723

    elias723

    Joined:
    Feb 10, 2006
    Posts:
    178
    Aha! I figured out what my problem was. I was doing my float-int conversions without the right cast on the receiving end. Therefore, it only would respond if the axes were at 1, 0, or -1. Just needed a little 7 letter fix in the code.
     
  6. elias723

    elias723

    Joined:
    Feb 10, 2006
    Posts:
    178
    As a summary of what I am working on for those interested:

    In my project, what I currently have is the client telling the server what the axes are that the client end user is pressing. These controls are interpreted by the server and then a FPS prefab moves around based on what was pressed. The client window does nothing but sends the controls.

    I am now looking at what code I need to add to my client and server scripts to allow my server to tell the client what buttons were pressed for each player, and move things around in the client window. Then, I can implement my control scripts (weapons, moving, anything that needs to use the "Input" class) to work around the server-client relationship.

    The major things still to complete will be getting the clients and server talking back and forth and making sure that nothing happens in one client that doesn't happen in another.
     
  7. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    This approach will have some problems: If the clients have different latencies, they may move differently. This will also be the case for LAN games. Especially if you have people colliding. since you don't have perfect frame syncing, player A can start moving forward at slightly different times on Player B and Player C, resulting in different positions. These errors will acumulate.

    A better approach might be to have the server send messages of [position, speed] to the clients. the clients will then set the positions from that. This way, the errors will not accumulate. If you want to be even cleverer, try sending [time, position, speed] - then each client can set position to be :

    position = serverPosition + (Time.time - serverTime) * serverSpeed

    This will work quite well....
     
  8. elias723

    elias723

    Joined:
    Feb 10, 2006
    Posts:
    178
    Thanks nicholas. I've heard of that, but it seems like if I want to do any kind of animation I won't be able to pull it off with that, since they won't necesarily line up. I guess that doesn't really matter at this point - I should just focus on getting a working example going. I actually came up with a real game (ie not just an example) to implement my networking on. I still haven't gotten the server talking back to the client yet, but it will be coming soon. Once I have that, the main thing will be getting the rest of the game set up.