Giter Club home page Giter Club logo

unity-transport-layer-udp-model's Introduction

GitHub license Issues Discord GitHub stars GitHub forks

The downside to using this project is the server will have Unity overhead, other than that, everything seems to work flawlessly.

Read this if you're interested in contributing.

Console Login Client Connecting Connected ClientDebug ServerDebug

unity-transport-layer-udp-model's People

Contributors

valkyrienyanko avatar

Stargazers

Tim Coster avatar Mehmet Gürdal avatar ZTIF avatar

Watchers

James Cloos avatar  avatar

unity-transport-layer-udp-model's Issues

Setting the Timeout Param in Driver()

How do you add or find the params to add for public NetworkDriver(INetworkInterface netIf, params INetworkParameter[] param);?

When I go to the meta data for INetworkParameter[] all I get is as follows.

#region Assembly Unity.Networking.Transport, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// Unity.Networking.Transport.dll
#endregion

namespace Unity.Networking.Transport
{
    public interface INetworkParameter
    {
    }
}

How do you send and receive an array of bytes over the network?

Send

I want to send an array of bytes which contains a data type and the x, y, z position of a player. The data type tells us that this is of 'position' data, this value could be 1. For position data, x, y, and z are integers and can be values such as 1500, 20, -3000.

With the BitConverter, we can convert all our integers to byte arrays.

I found that the Unity DataStreamWriter class has a public bool WriteBytes(NativeArray<byte> value); method, so we can use that to send the bytes of data over the network.

Below is what I have so far.
https://github.com/valkyrienyanko/Prototype/blob/4762ead183cbb3c2d23dfcd4519318e55127ba59/Assets/Workspace/Scripts/Client.cs#L51-L66
I'm adding the byte arrays to a list to combine them all into one big byte array. Then I am passing that to the new NativeArray<byte>(bytes.ToArray(), Allocator.Persistent); and finally we write that data to the writer.

Note that I still have yet to see if this data makes it all in one piece on the server side.

Note that I am using the new Unity Transport Layer minimal client-server example. You can learn more about it here.

Receive

I found that the DataStreamReader class has a public void ReadBytes(NativeArray<byte> array); and it's asking for NativeArray<byte> array as a param, but my question is how do you know what your going to put in there if you're already receiving the array?

Loading Commands Dynamically

Cleaner Server Logs

Right now the the server logs look like this. (ugly)
preview

With the -logFile param I was able to move these logs to a log.txt file. Now all I have to do is format the logs and spit them out somewhere else. Or I could turn the server build into a graphical console interface.

Multiple Console Lines Per Console Message

Multiple Console Lines Per Console Message

Note that the console can currently only print 1 line that spans across the entire width of the screen. There is no functionality for printing more then one line to console yet. This would require line detection when the characters get off the screen.

Update* I figured out how to detect how many lines there need to be per console message. I also figured out how to size the message box height out according to the number of lines. The only problem is when 2 big messages are sent, they overlap.
https://github.com/valkyrienyanko/Prototype/blob/25fd654754e973394215625cc109a6fa6d29ec6d/Server/Assets/Scripts/Console.cs#L49-L63

Building Resource Folder Takes Forever

The project build takes 2 minutes to build the resource folder on a empty Unity project. 2 minutes might not sound like a long time to you but when you're constantly rebuilding and testing, it is painfully long. I have no lead to why this is happening.

Here are links to other people having similar problems.

https://forum.unity.com/threads/addressables-building-resources-folder-takes-forever-android-build-process.875302/

https://answers.unity.com/questions/706674/unity-freezes-when-building-a-project-when-buildin.html

Native Collection has not been Disposed

First Encounter

I'm trying to stop the server properly, just doing Driver.Dispose() does not seem to be the way. Note that it is not clear exactly when this error occurs, you may have to run start and stop several times before the error occurs.

Steps to Reproduce

  1. Run server standalone.
  2. Run stop in console
  3. Run start in console
  4. Error may appear if not then repeat steps 2 to 3.

Second Encounter

  1. Run client. (Do not start server)
  2. Load main menu scene.
  3. Click on multiplayer.
  4. Wait for it to timeout and go back to main menu scene.
  5. Click on options scene. (Error appears)
  6. Press Esc to go back (Error appears)
  7. Click on options scene again (Error appears) etc..

Error

A Native Collection has not been disposed, resulting in a memory leak. Enable Full StackTraces to get more details.

Modular Commands

Modular Commands

Right now all commands are in a switch statement in https://github.com/valkyrienyanko/Prototype/blob/master/Server/Assets/Scripts/Console.cs

It would be nice if they were spread across several files.

Take the following structure layout as an example.

Scripts/
+-- Server.cs
+-- Commands/
|   +-- Kick.cs
|   +-- Exit.cs

Each command should have a name, a usage showing the args syntax, and a description of how to use the command. The commands should be stored in a collection so we can type help commandname to get more info on how to use that command.

Resetting event queue with pending events

Steps to reproduce

  1. Start server
  2. Start client
  3. Connect client to server
  4. Observe client and server sending and receiving data every 1 seconds.
  5. Kick the client from the server console.
  6. Error gets spammed in console every 1 seconds until client times out.
Resetting event queue with pending events (Count=1, ConnectionID=0) Listening: 1
UnityEngine.Debug:LogError(Object)
Unity.Networking.Transport.NetworkLogger:DumpToConsole() (at Library/PackageCache/[email protected]/Runtime/NetworkLogger.cs:55)
Unity.Networking.Transport.LogJob:Execute() (at Library/PackageCache/[email protected]/Runtime/NetworkDriver.cs:585)
Unity.Jobs.JobStruct`1:Execute(LogJob&, IntPtr, IntPtr, JobRanges&, Int32)
Unity.Jobs.JobHandle:ScheduleBatchedJobsAndComplete(JobHandle&)
Unity.Jobs.JobHandle:Complete()
Server:Update() (at Assets/Workspace/Scripts/Server.cs:90)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.