# C# Multiplayer Errors

**URL:** https://discussions.unity.com/t/c-multiplayer-errors/28896
**Category:** Questions & Answers
**Created:** [September 23, 2011, 1:43am UTC](https://discussions.unity.com/t/c-multiplayer-errors/28896 "2011-09-23T01:43:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![system](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/system/32/97283_2.png) [@system](https://discussions.unity.com/u/system)
#### Post date: [September 23, 2011, 1:43am UTC](https://discussions.unity.com/t/c-multiplayer-errors/28896/1 "2011-09-23T01:43:04Z")

</div>

hey guys, i’m new here and was wondering if u could help me out with this code:

```
using UnityEngine;
using System.Collections;
using System;

public class MPBase : MonoBehaviour
{

    public string connectToIP = "127.0.0.1";
    public int connectPort = 25000;
    public bool useNAT = false;
    public string ipaddress = "";
    public string port = "";

    string playerName = "<NAME ME>";

    void onGUI()
    {
        if (Network.peerType == NetworkPeerType.Disconnected)
        {
            if (GUILayout.Button("Connect"))
            {
                if (playerName != "<NAME ME>")
                {
                    Network.useNat = useNAT;
                    Network.Connect(connectToIP, connectPort);
                    PlayerPrefs.SetString("playerName", playerName);
                }
            }
            if (GUILayout.Button("Start Server"))
            {
                if (playerName != "<NAME ME>")
                {
                    Network.useNat = useNAT;
                    Network.InitializeServer(32, connectPort);

                    foreach (GameObject go in FindObjectsOfType(typeof(GameObject)))
                    {
                        go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
                    }
                    PlayerPrefs.SetString("PlayerName", playerName);
                }
            }
            playerName = GUILayout.TextField(playerName);
            connectToIP = GUILayout.TextField(connectToIP);
            connectPort = Convert.ToInt32(GUILayout.TextField(connectPort, ToString()));
        }
        else
        {
            if (Network.peerType == NetworkPeerType.Connecting) GUILayout.Label("Connect Status: Connecting");
            else if (Network.peerType == NetworkPeerType.Client)
            {
                GUILayout.Label("Connection Status: Client!");
                GUILayout.Label("Ping To Server: " + Network.GetAveragePing(Network.connections[0]));
            }
            else if (Network.peerType = NetworkPeerType.Server)
            {
                GUILayout.Label("Connection Status: Server!");
                GUILayout.Label("Connections: " + Network.connections.Length);
                if(Network.connections.Length >= 1)
                    GUILayout.Label("Ping To Server: " + Network.GetAveragePing(Network.connections[0]));
            }

            if (GUILayout.Button("Disconnect"))
                Network.Disconnect(200);

            ipaddress = Network.player.ipAddress;
            port = Network.player.port.ToString();
            GUILayout.Label("IP Address: " + ipaddress + " : " + port);
        }
    }

    void OnConnectedToServer()
    {
        foreach (GameObject go in FindObjectsOfType(typeof(GameObject)))
        {
            go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
        }
    }
}

```

125 ![alt text](http://s1234.photobucket.com/albums/ff414/trem1702/?action=view&current=MultiplayerErrors.png)125

---

<div class="post-metadata">

### Author: ![mohanrao164](https://avatars.discourse-cdn.com/v4/letter/m/7993a0/32.png) [@mohanrao164](https://discussions.unity.com/u/mohanrao164)
#### Post date: [September 23, 2011, 5:23am UTC](https://discussions.unity.com/t/c-multiplayer-errors/28896/2 "2011-09-23T05:23:24Z")

</div>

replace this code with yours

connectPort = Convert.ToInt32(GUILayout.TextField(connectPort.ToString()));

else if (Network.peerType == NetworkPeerType.Server)

i think above two lines where u got the error so replace those lines with these these lines  
you will rectify ur errors.

these are simple errors

in first line instead of “.” u have taken ",’

in second u have missed “=” this sign

so u got the errors

---

<div class="post-metadata">

### Author: ![mohanrao164](https://avatars.discourse-cdn.com/v4/letter/m/7993a0/32.png) [@mohanrao164](https://discussions.unity.com/u/mohanrao164)
#### Post date: [September 23, 2011, 12:49pm UTC](https://discussions.unity.com/t/c-multiplayer-errors/28896/3 "2011-09-23T12:49:09Z")

</div>

hello term1702 it is a simple one

you are using “onGUI” change it into “OnGUI” it will work.

u have taken small “o” instead of capital “O”.

---

<div class="post-metadata">

### Author: ![mohanrao164](https://avatars.discourse-cdn.com/v4/letter/m/7993a0/32.png) [@mohanrao164](https://discussions.unity.com/u/mohanrao164)
#### Post date: [September 26, 2011, 5:02am UTC](https://discussions.unity.com/t/c-multiplayer-errors/28896/4 "2011-09-26T05:02:37Z")

</div>

hello term1702

i think u did not given the ip address correct.

the default ip address is given as “127.0.0.1” now change this one to to your local ip address such as “196.168.0.1” the given one is just an example so u can use your local ip address that u want to connect to your system to another system.
