First of all sorry for my English. I have tried both of System.Net.Sockets.UdpClient and NetworkTransport. There is no problem with UdpClient really smooth no lag. (1 client, (200 Vector3)*9 per second) But when I try to do the same test with NetworkTransport it's very laggy. (Unreliable Channel)(3 to 5 second delay and really laggy) (I'm using same serialization method for both methods.) I don't understand why even LLAPI is very slow. After all, both of them are UDP. Right? Edit: I think the problem is about Update Method. It's able to receive just one data per frame.
FixedUpdate is running once per frame, not Update. If you are using same serialization method (with same async) problem may be somewhere else. Where? Hard to find out without a code and more data, like testing on one machine locally or via real net ?
You have things reversed: Update() is run once per frame, FixedUpdate() is run once per a set fixed rate ( hence the name) . The fixed rate is set by the Time->Fixed Timestep. This value defines the physics update rate too
Sorry for my late reply. I was studying for my exams. I have my own NetworkManager. It's based on Server/Client system. It can adapt to any kind of Networking infrastructure. I have some Objects(Class) that called as "NObject". It basically stores some data for sync. And NClientEye manages those objects. First, I built it on Unity Networking(LLAPI). Then I tried it with (1 client, (200 Vector3)*9 per second). To do this have created 200 NObject. And I did set NTransform update rate of those objects as 9 Update per second. Then I connected a client(local). And I wrote a basic script to move objects forward and backward. In Unity.Networking was lagging and moving like every 0.5 seconds. (There is no FPS drop) Then I have tried it with a basic UdpClient(System.Net.Sockets) Same system, same codes, same serialization methods. No difference except Library. And everything was fine. There was no lag or delay, everything very smooth. Everything same except those two parts. UDP codes: Code (CSharp): /* ----------------------- UDP-Send ----------------------- // [url]http://msdn.microsoft.com/de-de/library/bb979228.aspx#ID0E3BAC[/url] */ using UnityEngine; using System.Collections; using System.Collections.Generic; using System; using System.Text; using System.Net; using System.Net.Sockets; using System.Threading; using UnityEngine.Networking; public class UDP : MonoBehaviour { public ServerManager manager; public string IP; public int port; UdpClient myClient; public List<NetworkMessage> allReceivedUDPPackets = new List<NetworkMessage>(); private object _sync = new object(); public void Start() { manager = GetComponent<ServerManager>(); init(); } // init public void init() { receiveThread = new Thread( new ThreadStart(receiveData)); receiveThread.IsBackground = true; receiveThread.Start(); } // sendData public static void sendData(UdpClient client, Message msg) { try { //IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse(IP), port); NetworkWriter writer = new NetworkWriter(); msg.Serialize(writer); byte[] data = writer.AsArray(); client.Send(data, data.Length); } catch (Exception err) { print(err); } } private void Update() { lock (_sync) { for (int i = 0; i < allReceivedUDPPackets.Count; i++) manager.Message(allReceivedUDPPackets[i]); allReceivedUDPPackets.Clear(); } } Thread receiveThread; private void receiveData() { myClient = new UdpClient(port); while (true) { try { IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0); byte[] data = myClient.Receive(ref anyIP); NetworkReader reader = new NetworkReader(data); NetworkMessage msg = new NetworkMessage(); msg.reader = reader; lock (_sync) { allReceivedUDPPackets.Add(msg); } } catch (Exception err) { print(err.ToString()); } } } private void OnDisable() { Close(); } private void OnApplicationQuit() { Close(); } void Close() { receiveThread.Abort(); myClient.Close(); } } Unity.Networking Receive codes: Code (CSharp): void Update() { int recHostId; int connectionId; int channelId; byte[] recBuffer = new byte[3072]; int bufferSize = 3072; int dataSize; byte error; NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error); switch (recData) { case NetworkEventType.ConnectEvent: //2 OnConnect(connectionId); break; case NetworkEventType.DataEvent: //3 NetworkReader reader = new NetworkReader(recBuffer); NetworkMessage msg = new NetworkMessage(); msg.reader = reader; Message(msg); break; case NetworkEventType.DisconnectEvent: //4 OnDisconnect(connectionId); break; } } 200 FPS on the client. And its receive just one message per frame. I have 200*9 message per second. (1800 message per second). 1800-200 = 1600 lost message. So it's not enough to receive all the messages. This explains why some objects don't sync at the time. But the part I couldn't understand why there is a delay. I mean even after objects stop moving on the server side, some objects still moving with a delay on the client side. It's like there's a queue. but I'm using the Unreliable channel. If I can't find any solution then I have to write my own Networking system and Connection manager based on System.Net.Sockets.
At First, I suspected about this too. But its works right. Code (CSharp): config.Channels.Clear(); config.AddChannel(QosType.Unreliable); config.AddChannel(QosType.UnreliableFragmented); config.AddChannel(QosType.UnreliableSequenced); config.AddChannel(QosType.Reliable); config.AddChannel(QosType.ReliableFragmented); config.AddChannel(QosType.ReliableSequenced); config.AddChannel(QosType.StateUpdate); config.AddChannel(QosType.ReliableStateUpdate); config.AddChannel(QosType.AllCostDelivery); I am using channel 0 to send Unreliable Message.
Hello, I was having some trouble with this and in my opinion it's due to poor documentation on the transport layer. Using the documentation example, you'll find that the server is only processing 1 packet per frame in Update. I checked the HLAPI's source to find unity's own solution. Implement a loop to process queued packets and the delay should go away. Code (CSharp): private void Update() { NetworkEventType fromHost; do { int connectionId; int channelId; int receivedSize; fromHost = NetworkTransport.ReceiveFromHost(this.m_ServerHostId, out connectionId, out channelId, this.m_MsgBuffer, this.m_MsgBuffer.Length, out receivedSize, out error); if (fromHost == NetworkEventType.Nothing) ; switch (fromHost) { case NetworkEventType.DataEvent: this.HandleData(connectionId, channelId, receivedSize, error); goto case NetworkEventType.Nothing; case NetworkEventType.ConnectEvent: this.HandleConnect(connectionId, error); goto case NetworkEventType.Nothing; case NetworkEventType.DisconnectEvent: this.HandleDisconnect(connectionId, error); goto case NetworkEventType.Nothing; case NetworkEventType.Nothing: continue; default: if (LogFilter.logError) { Debug.LogError((object)("Unknown network message type received: " + (object)fromHost)); goto case NetworkEventType.Nothing; } else goto case NetworkEventType.Nothing; } } while (fromHost != NetworkEventType.Nothing); }