Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

question about Network.InitializeServer

Discussion in 'Multiplayer' started by rmbunity, Dec 4, 2007.

  1. rmbunity


    Dec 1, 2007
    My script is below. It is attached to the camera which is the only object.
    When play starts, the console shows the output from the 2 prints. But, no
    sever seems to be listening on port 2500. I have briefly explored the NAT
    stuff but don't think I need it here. I would be happy to see an open socket
    on port 2500 via localhost/
    Thanks for any insights.

    function Start() {
    // Network.useNat = !Network.HavePublicAddress();
    var rc = Network.InitializeServer(5,2500); // start my own server
    print("RC=" + rc);
  2. larus


    Unity Technologies

    Oct 12, 2007
    If you run that script, a server should start listening on port 2500. Just as long as you get RC=NoError or something similar printed to the debug log.

    To "see" the port has opened, open a terminal window and run
    Code (csharp):
    1. netstat -n | grep 2500
    You should see a line printed indicating that someone is listening on that port. It does not bind to localhost specifically but to any interface (*). If you don't see the port has opened you presumably have an error printed after "RC="?
  3. rmbunity


    Dec 1, 2007
    Thanks for the response. This is very helpful. The RC is indeed NoError.
    And, a UDP port 2500 port is there. I had been looking for a TCP port.

    If you don't mind continuing the thread for a moment, in the same script, I next
    added this line after printing the RC from the InitializeServer:
    Network.Connect("",2500); // now start client
    I experimented with various IPs including localhost,, etc but was not
    successful. Now I know that technically you don't really "connect" to a UDP port,
    but I am aware that you can execute a connect to one to tie down the
    association. Anyway, I am not sure what Network.Connect is actually doing
    internally. I just know that the docs tell me:

    To create the server, you simply call Network.InitializeServer() from a script. When you want to connect to an existing server as a client, you call Network.Connect() instead.

    So, I am unsure how to accomplish the connect.

    Thanks very much.
  4. rmbunity


    Dec 1, 2007
    Never mind. :)
    I answered my own question. I found that I could start 2 separate instances
    of Unity, one running the InitializeServer and the other running the Connect.
    Both work fine now.