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. Dismiss Notice

does not exist in the namespace 'System' error

Discussion in 'Scripting' started by Baezzae, Dec 2, 2014.

  1. Baezzae

    Baezzae

    Joined:
    Sep 21, 2014
    Posts:
    1
    i'm studying part of unity Network basic.

    and coding example source.

    few days ago i find the source one of example.

    after coding run this example. i have some errors...

    the general error is does not exist in the namespace 'System'...

    i check the spell, folder. files...

    i can't 'System.Net.IPAddress' file...

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Net.Sockets;
    4. using System.Net;
    5.  
    6. public class SimpleClient : MonoBehaviour {
    7.    
    8.     public string m_IPAddress = "127.0.0.1";
    9.     public const int kPort =10523;
    10.     private static SimpleClient singleton;
    11.     private Socket m_socket;
    12.    
    13.    
    14.     void Awake()
    15.     {
    16.         //소켓을 생성합니다.
    17.         m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    18.         System.Net.IPAddress
    19.                 remoteIPAddress = System.IPAddress.Parse(m_IPAddress);
    20.         System.Net.IPEndPoint
    21.             remoteEndPoion = new System.Net.IPEndPoint(remoteIPAddress, kPort);
    22.         singleton = this;
    23.         //서버에 연결 요청을 합니다.
    24.         m_Socket.Connect(remoteEndPoint);
    25.         Debug.Log("Connecting");
    26.     }
    27.    
    28.     void OnApplicationQuit()
    29.     {
    30.         m_Socket.Close();
    31.         m_Socket = null;
    32.     }
    33.    
    34.     void Update()
    35.     {
    36.         //마우스가 왼쪽 클릭 때마다 현재 마우스 좌표와 Hello 문자열을 서버에게 보냄.
    37.         if(Input.GetMouseButtonUp(0))
    38.         {
    39.             MessageData newmsg = new MessageData();
    40.             newmsg.stringData = "hello";
    41.             newmsg.mousex = Input.mousePosition.x;
    42.             newmsg.mousey = Input.mousePosition.y;
    43.             newmsg.type = 0;
    44.             SimpleClient.Send(newmsg);
    45.     }
    46.    
    47. }
    48.    
    49.     static public void Send(MessageData msgData)
    50.     {
    51.         if(singleton.m_Socket == null)
    52.             return;
    53.        
    54.         byte[] sendData = MessageData.ToByteArray(msgData);
    55.         byte[] prefix = new byte[1];
    56.         prefix[0] =(byte)sendData.Length;
    57.         singleton.m_Socket.Send(prefix);
    58.         singleton.m_Socket.Send(sendData);
    59.         //LOG
    60.         Debug.Log(msgData.stringData + " " + msgData.mousex.ToString() + " " + msgData.mousey.ToString() );
    61.     }
    62. }


    and my unity version is 4.0.0f7
     
  2. Kirk Clawson

    Kirk Clawson

    Joined:
    Nov 4, 2014
    Posts:
    65
    On line 19, you have
    That should be
    Though, since you have System.Net in your using statements, all of the instances of System.Net. could just be removed, and it will still work fine.
     
  3. zRedCode

    zRedCode

    Joined:
    Nov 11, 2013
    Posts:
    131
    why you constantly write namespaces even if you have incapsulated it in the usings?
    Code (CSharp):
    1. remoteIPAddress = System.Net.IPAddress.Parse(m_IPAddress);
    You can simply write:
    Code (CSharp):
    1. remoteIPAddress = IPAddress.Parse(m_IPAddress);
    Because the namespace is declared in the top lines of the file.