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

TCP connection interfering with UDP?

Discussion in 'Multiplayer' started by Hermonirr, Sep 18, 2019.

  1. Hermonirr

    Hermonirr

    Joined:
    Dec 23, 2013
    Posts:
    56
    I need help regarding socket communication, udp, tcp, arducopter, mavproxy and sim vehicle.
    If you're still rading this, here is the problem.

    I'm using Unity as the physics engine for a simulated quadcopter drone. It interfaces with arducopter, a flight controller, via a UDP socket on ports 9002 and 9003. My script sends the drone data - position, orientation, motion vector - and gets back the forces that should be applied to the motors to achieve the flight plan.

    This works fine.

    I'm also sending images from the drone cameras in Unity to another program. This is done with a TCP client that connects to a TCP server on port 8010 and starts sending the byte array containing the images.

    Here is the problem:
    As soon as I'm starting the TCP connection, arducopter gets NaN and infinite values on its UDP link, resulting in communication loss and intense human frustration.

    The ports are not the same. The protocol is not the same. Why does data sent on one channel interferes with another channel?

    Thanks
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,062
    Any shared memory / buffers?
     
  3. Hermonirr

    Hermonirr

    Joined:
    Dec 23, 2013
    Posts:
    56
    None that I've created, separate scripts on separate game objects.
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Might need to show the code. Your TCP and UDP communications should really have nothing to do with each other, even if you were using the same port numbers (UDP ports and TCP ports are separate things even though they are used in a similar manner).
     
  5. aabramychev_

    aabramychev_

    Joined:
    May 10, 2019
    Posts:
    16
    the deal is in the nature of tcp, tcp was develop for big files fast delivering, so during transmitting tcp is trying to occupy the whole bandwidth which you have, and does not give any chance for udp to survive...

    There re solutions of this problem
    1. add yours congestion control to tcp (each time when yo send portion of data - wait... for example 1 k tcp per frame
    2. send your file by using udp (reliable udp)
    3. change you udp communication to tcp...

    Hope it helps
     
    Last edited: Sep 19, 2019
    TwoTen and Joe-Censored like this.
  6. MrsPiggy

    MrsPiggy

    Joined:
    Jun 13, 2018
    Posts:
    154
    The same could be said for the other way around: UDP has no congestion control at all so it can saturate your bandwidth and make every other connection slow or unresponsive. And it gets much worse than with TCP which respects the limits of your bandwidth.

    @Hermonirr I think one of the answers to your question depends on how much bandwidth you've available. If there's not enough for all the data you're sending, problems will arise no matter what protocol you're using.

    Switching to a single protocol (TCP or UDP) (as @aabramychev_ suggested) may be worth trying.
     
    aabramychev_ likes this.
  7. Hermonirr

    Hermonirr

    Joined:
    Dec 23, 2013
    Posts:
    56
    Thanks for your suggestions. I will try them as soon as I get back from Unite Copenhagen (yoohoo!!)

    In any case, here is my relevant code. Note that in the actual project the _Help postfix for some of the files is not present, I added it to the duplicates so I could remove irrelevant code safely.
     

    Attached Files:

  8. Hermonirr

    Hermonirr

    Joined:
    Dec 23, 2013
    Posts:
    56
    The problems is fixed, I made the drone the TCP server and the client connects to it. This works fine. I don't know why.