Giter Site home page Giter Site logo

tcp-udp-networking's Introduction

Important!

I've created a new, way better networking solution, RiptideNetworking, along with improved tutorials on how to use it.

C# Networking Tutorial Series

This is the source code for my C# networking tutorial series on YouTube.

Each branch contains the code corresponding to what you should have at the end of each video in the series.

Video Branch
Part 1 tutorial-part1
Part 2 tutorial-part2
Part 3 tutorial-part3
Part 4 tutorial-part4
Part 5 tutorial-part5
Part 6 tutorial-part6
Part 7 tutorial-part7
Part 8 tutorial-part8
Part 9 tutorial-part9
Part 10 tutorial-part10
Part 11 tutorial-part11

Note: using the console app server in the GameServer project (from any branch) with the GameClient project from branch 6 and up will produce errors. This is because after part 5 of the series, we moved the server code into Unity and stopped updating the console server.

Unity Version: 2018.3.7

tcp-udp-networking's People

Contributors

shreyanshanchlia avatar tom-weiland avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tcp-udp-networking's Issues

Encrypted packets

Hi, I commented on your latest video about encryption.

As I said in that comment, I have a working solution for TCP, however it doesn't really work for UDP.
My plans are to do something different for our game, and just have an additional transport layer. Secure TCP, TCP and UDP.

If you want I can try to create a pull request with the same changes that I have. Maybe someone from your discord have some better ideas and/or a solution to the UDP issue I am seeing.

To add basic support for it in TCP, not that many lines of code is required. However I also did some changes to try to stop replay attacks. It's not very complicated either, just not very pretty at the moment. Since I decided to use AES, there are some obvious issues that could be encountered as well, so I will try to document why some of the things are the way they are.

I will have to spend some time to adopt it to this repo (we also only use the console server). I probably should make sure I change it for both here. Let me know if you think this is just a waste of time, or if it could help. Since you helped me finally getting a proper Server-Client boilerplate going, I feel like I should give something back :)

UDP client does not work when server is deployed to a remote location

Summary

When you deploy the game server to a remote ip, the UDP client does not connect successfully.

This is due to this line
https://github.com/tom-weiland/tcp-udp-networking/blob/master/GameClient/Assets/Scripts/Client.cs#L207
always instantiating the ip endpoint to 127.0.0.1, since it fires before the assigning of the ip address on the instance.

I just spent quite a few hours going down a socket debugging rabbithole, when the error was in fact super simple, mainly due to the lack of helpful error messages(and lack of knowledge I suppose), so I'm hoping it can be helpful to you or others.

Reproduction

  • Start the server on any other machine than localhost
  • Attempt to connect with client
  • UDP client instantly disconnects, and in turn, the client disconnects.

Proposed solution

Personally I moved the line in question into the connect function, and it appears to work as expected. It just needs to be called after the client instance ip has been set.

Note

Thank you for the repo and videos, it has been really helpful in getting a basic setup working quickly.

Problem with ditcionaries?

Error receiving data from client via UDP: System.Collections.Generic.KeyNotFoundException: The given key '0' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)

is showing up when I connect via UDP.

License?

Would be nice to have a LICENSE file to know what we can and cannot do with this code. As it is, it's under exclusive copyright to you not allowing any one to use, share, or modify it.

Even if that is your intent, it'd be appreciated if it was explicitly stated in a LICENSE file. I feel it is especially important as you are using this in a tutorial series where it is very likely people will be using, sharing, and modifying your code regardless of which license you choose to place it under anyway.

I believe you also said it is based on someone else's code? In which case you'll have to use a compatible license, or possibly the same one as them.

Crashing NetCore Version

Howdy,

I followed your tutorial and then downloaded your files here.
I replaced my project clientside with yours and server side with yours.

While I am able to run the unity version of the server without crashes and I am getting a crash with the netcore version.

If I attempt to move I get a key error has to the with the packet dictionary I believe I will attempt to fix it myself but not familiar with netcore.. usually I would use framework.

image

WebGL support

Running a WebGL build (of the example GameClient) throws an exception:

SocketException: Success
at System.Net.Sockets.Socket..ctor (System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType) [0x00000] in <00000000000000000000000000000000>:0

WebGL seems to not support TCP and UDP connections due to security reasons.

It would seem that for WebGL, Websockets (WSS) and WebRTC seem to be the way to go.

I know the project is called tcp-udp- networking, but would there be any interest in extending support to WSS/WebRTC as well?

I will examine this myself and try to come up with a solution if feasible. In case I'm successful, I'll open a pull request.

I would definitely welcome any feedback on the matter, especially if I'm missing something here and there is a simpler way to achieve WebGL support.

[Question] Would it be possible to have all the server and client code in one Unity Project?

I noticed that the server needs to have the player and map hitboxes (I'm sure this is to manage collision detection server side)

I'm also assuming that this will eliminate hacks like being able to walk through walls (As for example if you had no geometry on the server it could not tell if a player was wanting to walk through a wall)

So my question is would it be possible to have both server and client in a single project instead of two?

I think this would help in a more long term project (As the assets increase in number and size, you will be having 2 copies of each and the project size will start to grow)

Null object not set to an instance of an object

NullReferenceException: Object reference not set to an instance of an object UIManager.ConnectToServer () (at Assets/Scripts/Network/UIManager.cs:30) UnityEngine.Events.InvokableCall.Invoke () (at <9244fb8344e84288877b43b45b29c242>:0) UnityEngine.Events.UnityEvent.Invoke () (at <9244fb8344e84288877b43b45b29c242>:0) UnityEngine.UI.Button.Press () (at Library/PackageCache/[email protected]/Runtime/UI/Core/Button.cs:70) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at Library/PackageCache/[email protected]/Runtime/UI/Core/Button.cs:114) UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/[email protected]/Runtime/EventSystem/ExecuteEvents.cs:57) UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction1[T1] functor) (at Library/PackageCache/[email protected]/Runtime/EventSystem/ExecuteEvents.cs:272)
UnityEngine.EventSystems.EventSystem:Update() (at Library/PackageCache/[email protected]/Runtime/EventSystem/EventSystem.cs:501)`

I keep geting this is error saying null object not set to an instance of an object, the code is the exact same as yours, I even tried copy and pasting it. The ui manager is a component of the canvas and the start menu is referenced to the child game object holding the button and the input field, but it's still giving me this error. That or this error doesn't have to do with the code and i'm an idiot since I am no expert in unity.

If it is because of the code, I attached the code of the code up until you tested it for the first time, or at 13:09 of the part 2 youtube video. I hope i'm not bothering you and have a nice day.

code.zip

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.