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

Udp how does the server know its clients?

Discussion in 'Multiplayer' started by dudinirgad, Jul 21, 2017.

  1. dudinirgad

    dudinirgad

    Joined:
    Jul 19, 2017
    Posts:
    5
    Surely in TCP I can just save instance of TCPClient when a user connects thry my listener..

    But how does it work for udp?
    Say I have a pong game I tell the server to wait for 2 different clients sending a 'Joined'
    Packet before sending back a 'Game Start' packet to init game variables.

    How do I tell the clients apart ?
    And not same clients sending few 'Joined' packets.. etc.
     
  2. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    UdpClient?
    https://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient(v=vs.110).aspx
     
  3. jemonsuarez

    jemonsuarez

    Joined:
    Sep 24, 2012
    Posts:
    151
    Hi @dudinirgad the UDP transport protocol doesn't establishes a connection as TCP does, so you don't have the confirmation packages or disconnection events.
    UDP is useful when you have to transfer some massive data locally, as video frames, so if some of them are lost it doesn't matters. Also UDP clients cane start or stop listening at any time.
    If you need a reliable connection, keep using TCP, or you will have to implement some confirmation and timeout procedures.
    Chose the appropriate protocol depending on your needs.
    Best regards.