Search Unity

Networking is not working on standalone.

Discussion in 'Multiplayer' started by Neopolita, Apr 15, 2009.

  1. Neopolita

    Neopolita

    Joined:
    Apr 15, 2009
    Posts:
    5
    Hello, I am working on a multiplayer game, I have developed a server with Python and all is working great when I test from the IDE but when I run a standalone version of my application it doesn't receive any data from the server, somebody has experienced this problem? Thanks.
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    I guess you use regular .NET TCP sockets in Unity Desktops for the communication?
     
  3. Neopolita

    Neopolita

    Joined:
    Apr 15, 2009
    Posts:
    5
    Yes, I am using regular .NET sockets.
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Did you add debug output to see if connection is beeing established or blocked by the firewall for example?
     
  5. Neopolita

    Neopolita

    Joined:
    Apr 15, 2009
    Posts:
    5
    I am working in local.
     
  6. Kaiserludi

    Kaiserludi

    Joined:
    Jan 21, 2009
    Posts:
    94
    Are you using the sockets directly or through tcpclient/udpclient classes?
    First way works fine for us, last way is making problems in Unity, although I can't remember if standalones belong to the platforms making trouble for tcpclient/udpclient.

    Do you speak about Windows or Mac standalone?
    It seems, that the mono versions are not identical for them.
     
  7. Neopolita

    Neopolita

    Joined:
    Apr 15, 2009
    Posts:
    5
    It's Mac Standalone, I am using Socket directly, all my operations are asynchronous (BeginConnect, BeginReceive, etc...) Thanks.
     
  8. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Are you on 2.5?
    Async sockets require 2.5, they were not full working before.

    A reason that they work in the editor is that the editor has further stuff injected that might compensate for something that is not taken into consideration with your code.

    there are two things to do in such a situation
    1. Create a minimum replication script / setup that you can use to file a bug report
    2. consider to post that script / setup here, perhaps even before filing a bug. Perhaps its something simple thats "broken".
     
  9. Neopolita

    Neopolita

    Joined:
    Apr 15, 2009
    Posts:
    5
    I am on 2.5, I will post the code this evening. Thanks a lot.
     
  10. dgish

    dgish

    Joined:
    May 2, 2009
    Posts:
    10
    Are they fully working in Unity iPhone 1.5?

    I have basic networking running between Unity iPhone and Unity 2.5, but it's been a tough slog. After discovering that NetworkView is unimplemented on the iPhone (even though there are no clues in the docs and it works fine in the IDE), I rolled my own using UdpClient.

    The problem is getting around blocking calls like Receive(). Unity iPhone only supports .NET 1.1, where UdpClient has zero support for async operation. No problem, you say, do your receiving in a thread. Yes, that works. But at shutdown time I can't kill the thread until Receive() times out. I stop the player and about a minute later the code, which isn't supposed to be running anymore, logs a message (mine) that the thread has returned. Unless there's some reliable way of killing a blocked thread in OnApplicationQuit(), I'm convinced non-blocking sockets are the ticket. I subclassed UdpClient to access the underlying socket (Client property) and set its Blocking property to false:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Net;
    4. using System.Net.Sockets;
    5.  
    6. public class MyUdpClient : UdpClient
    7. {
    8.  
    9.     public MyUdpClient() : base()
    10.     {
    11.     }
    12.    
    13.     public MyUdpClient(IPEndPoint localEP) : base(localEP)
    14.     {
    15.     }
    16.        
    17.     public void setBlockingOption(bool shouldBlock)
    18.     {
    19.         // Uses the protected Client property belonging to the UdpClient base class.
    20.         Socket s = this.Client;
    21.         // Set the blocking option.
    22.         s.Blocking = shouldBlock;
    23.         Debug.Log("Socket blocking option is now " + this.Client.Blocking);
    24.     }
    25. }
    26.  
    That works fine, but it doesn't change the behavior: Receive() still blocks (in both Unity iPhone and 2.5). So before I suck it up and rewrite the world (again) in low-level sockets:

    1. Do Mono sockets actually honor the Blocking setting? Any clue why changing it doesn't affect UdpClient's behavior?

    2. Is there a way to kill a blocked Thread?

    3. Alternatively, is there a way to check for available data before calling Receive()? (UdpClient does not support the Available property in .NET 1.1.)