Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

[Solved] Where is BasicNetworkDriver?

Discussion in 'Connected Games' started by zhuchun, Apr 17, 2019.

  1. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    345
    Hi, I have an existing project and I want to upgrade multiplayer to the latest since I'm moving to Unity 2019. After copied files to the package folder, the compiler says "The type or namespace name 'BasicNetworkDriver<>' does not exist in the namespace 'Unity.Networking.Transport'". I can't find any update in the manual as well, please help.

    networkDriver.png
     
  2. ARLS

    ARLS

    Joined:
    Jul 19, 2018
    Posts:
    1
    zhuchun and gooodpgr like this.
  3. zhuchun

    zhuchun

    Joined:
    Aug 11, 2012
    Posts:
    345
    Thank you @ARLS . NetworkPipeline is a cool feature. Here is a checklist for people who need to upgrade their projects from previous version.

    1. Upgrade to Unity 2019, follow the instruction and copy files.

    2. UdpNetworkDriver is a class now, so just delete
    Code (CSharp):
    1. using UdpNetworkDriver = Unity.Networking.Transport.BasicNetworkDriver<Unity.Networking.Transport.IPv4UDPSocket>;
    3. Use NetworkEndpoint instead of IPEndPoint(IIRC;)) where server/client starts.

    4. Use UdpNetworkDriver.CreatePipeline() to instantiate a pipeline, it comes with useful things like reliable packet and network simulate(latency/packet loss), but for upgrading purpose you can instantiate without any parameter first.

    5. UdpNetworkDriver.Send() now takes an extra NetworkPipeline parameter, use the one you just created.
     
    ZuhairGhias and gooodpgr like this.
  4. i2winners

    i2winners

    Joined:
    Apr 21, 2019
    Posts:
    1
    @zhuchun can you share some code sample

    Code (CSharp):
    1. using System.Net;
    2. using UnityEngine;
    3.  
    4. using Unity.Networking.Transport;
    5. using Unity.Collections;
    6.  
    7. using NetworkConnection = Unity.Networking.Transport.NetworkConnection;
    8. using UdpCNetworkDriver = Unity.Networking.Transport.BasicNetworkDriver<Unity.Networking.Transport.IPv4UDPSocket>;
    9.  
    10.  
    11.  
    12. public class ServerBehaviour : MonoBehaviour
    13. {
    14.  
    15.     public UdpCNetworkDriver m_Driver;
    16.     private NativeList<NetworkConnection> m_Connections;
    17.  
    18.     void Start()
    19.     {
    20.         m_Driver = new UdpCNetworkDriver(new INetworkParameter[0]);
    21.         if (m_Driver.Bind(new IPEndPoint(IPAddress.Any, 9000)) != 0)
    22.             Debug.Log("Failed to bind to port 9000");
    23.         else
    24.             m_Driver.Listen();
    25.  
    26.         m_Connections = new NativeList<NetworkConnection>(16, Allocator.Persistent);
    27.     }
    28.  
    to something like this?:
    Code (CSharp):
    1. using System.Net;
    2. using Unity.Collections;
    3. using UnityEngine;
    4. using Unity.Networking.Transport;
    5.  
    6.  
    7. public class ClientBehaviour : MonoBehaviour
    8. {
    9.     //You still define a UdpCNetworkDriver but instead of having a list of connections we now only have one.
    10.     //There is a Done flag to indicate when we are done, or in case you have issues with a connection, you can exit quick.
    11.  
    12.     public UdpNetworkDriver m_Driver;
    13.     public NetworkConnection m_Connection;
    14.     public NetworkPipeline m_Pipeline;
    15.     public bool m_Done;
    16.  
    17.     // Start by creating a driver for the client and an address for the server.
    18.     void Start()
    19.     {
    20.        
    21.         m_Driver = new UdpNetworkDriver(new INetworkParameter[0]);
    22.         m_Pipeline = m_Driver.CreatePipeline();
    23.         m_Connection = default(NetworkConnection);
    24.  
    25.         var endpoint = new NetworkEndPoint();
    26.         m_Connection = m_Driver.Connect(endpoint);
    27.     }
    28.     // Then call the Connect method on your driver.
    29.  
     
    ZuhairGhias likes this.
  5. Atriox

    Atriox

    Joined:
    Jul 13, 2013
    Posts:
    1
    After spending a little while toiling away at this I finally figured out how to get it working with some of the new updates after actually reading the source (I'm terrible at reading source :D).

    First off the proper way to use the NetworkEndPoint struct is this:

    Code (CSharp):
    1. m_Endpoint = new NetworkEndPoint();
    2. m_Endpoint = NetworkEndPoint.Parse("127.0.0.1", 9000);
    I'm linking gists of the non-jobified source for the client and server and hopefully it helps anyone else out with this! Also note you have to do something with the pipeline, just used what was in the documentation, not entirely sure how to do it with a different pipeline, nor do I fully understand it yet. Still reading :)

    ClientBehavior.cs:
    https://gist.github.com/duynguye/2ae6680068c44e574390d7e9874d4f83

    ServerBehavior.cs:
    https://gist.github.com/duynguye/7b6b0828a89ab4e4b7da769f86adc1fe
     
    Ghosthowl, consoni and zhuchun like this.