예제 #1
0
    void OnGUISelectHost()
    {
#if USE_TRANSPORT_TCP
        if (GUI.Button(new Rect(20, 40, 150, 20), "Launch server."))
        {
#else
        if (GUI.Button(new Rect(20, 40, 150, 20), "Launch Listener."))
        {
#endif
            m_transport.StartServer(m_port, 1);
            isSelected = true;
        }

        // 클라이언트를 선택했을 때 접속할 서버 주소를 입력합니다.
        m_strings = GUI.TextField(new Rect(20, 100, 200, 20), m_strings);
#if USE_TRANSPORT_TCP
        if (GUI.Button(new Rect(20, 70, 150, 20), "Connect to server"))
        {
#else
        if (GUI.Button(new Rect(20, 70, 150, 20), "Connect to terminal"))
        {
#endif
            m_transport.Connect(m_strings, m_port);
            isSelected = true;
            m_strings  = "";
        }
    }

    void OnGUIServer()
    {
#if USE_TRANSPORT_TCP
        if (GUI.Button(new Rect(20, 60, 150, 20), "Stop server"))
        {
#else
        if (GUI.Button(new Rect(20, 60, 150, 20), "Stop Listener"))
        {
#endif
            m_transport.StopServer();
            isSelected = false;
            m_strings  = "";
        }
    }

    void OnGUIClient()
    {
        // 클라이언트를 선택했을 때 접속할 서버의 주소를 입력합니다.
        if (GUI.Button(new Rect(20, 70, 150, 20), "Send message"))
        {
            byte[] buffer = System.Text.Encoding.UTF8.GetBytes("Hellow, this is client.");
            m_transport.Send(buffer, buffer.Length);
        }

        if (GUI.Button(new Rect(20, 100, 150, 20), "Disconnect"))
        {
            m_transport.Disconnect();
            isSelected = false;
            m_strings  = "";
        }
    }
}
예제 #2
0
파일: Sequence.cs 프로젝트: wyuurla/006772
    void OnUpdateDisconnection()
    {
        switch (hostType)
        {
        case HostType.Server:
            m_transport.StopServer();
            break;

        case HostType.Client:
            m_transport.Disconnect();
            break;

        default:
            break;
        }

        m_mode   = Mode.SelectHost;
        hostType = HostType.None;
        //serverAddress = "";
        // 호스트명을 가져옵니다.
        string hostname = Dns.GetHostName();

        // 호스트명에서 IP 주소를 가져옵니다.
        IPAddress[] adrList = Dns.GetHostAddresses(hostname);
        serverAddress = adrList[0].ToString();
    }
예제 #3
0
    void OnUpdateDisconnection()
    {
        switch (hostType)
        {
        case HostType.Server:
            m_transport.StopServer();
            break;

        case HostType.Client:
            m_transport.Disconnect();
            break;

        default:
            break;
        }

        m_mode   = Mode.SelectHost;
        hostType = HostType.None;
        //serverAddress = "";
        // 호스트명을 가져옵니다.
        string hostname = Dns.GetHostName();

        // 호스트명에서 IP 주소를 가져옵니다.
        IPAddress[] adrList = Dns.GetHostAddresses(hostname);
        serverAddress = adrList[0].ToString();
        foreach (IPAddress ip in adrList)  //IP v4
        {
            if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                serverAddress = ip.ToString();
            }
        }
    }
예제 #4
0
    void UpdateLeave()
    {
        if (isServer == true)
        {
            transport.StopServer();
        }
        else
        {
            transport.Disconnect();
        }

        state = ChatState.HOST_TYPE_SELECT;
    }
예제 #5
0
 void UpdateLeave()
 {
     if (m_isServer == true)
     {
         m_transport.StopServer();
     }
     else
     {
         if (m_transport.IsConnected())
         {
             m_transport.Disconnect();
         }
     }
     m_roomState = RoomState.SELECT_HOST;
     m_messages.Clear();
 }
예제 #6
0
파일: Chat.cs 프로젝트: leerang92/StudyRepo
    void UpdateLeave()
    {
        if (m_isServer == true)
        {
            m_transport.StopServer();
        }
        else
        {
            m_transport.Disconnect();
        }

        // 메시지 삭제.
        for (int i = 0; i < 2; ++i)
        {
            m_message[i].Clear();
        }

        m_state = ChatState.HOST_TYPE_SELECT;
    }
예제 #7
0
파일: Network.cs 프로젝트: SHSongs/DoorPi9
 public void Disconnect()
 {
     m_transport.Disconnect();
 }
예제 #8
0
    // Update is called once per frame
    void Update()
    {
#if USE_TRANSPORT_TCP
        if (m_transport != null && m_transport.IsConnected() == true)
        {
#else
        if (m_transport != null)
        {
#endif
            byte[] buffer   = new byte[m_mtu];
            int    recvSize = m_transport.Receive(ref buffer, buffer.Length);
            if (recvSize > 0)
            {
                string message = System.Text.Encoding.UTF8.GetString(buffer);
                Debug.Log(message);
            }
        }
    }

    void OnGUI()
    {
        if (isSelected == false)
        {
            OnGUISelectHost();
        }
        else
        {
            if (m_transport.IsServer() == true)
            {
                OnGUIServer();
            }
            else
            {
                OnGUIClient();
            }
        }
    }

    void OnGUISelectHost()
    {
#if USE_TRANSPORT_TCP
        if (GUI.Button(new Rect(20, 40, 150, 20), "Launch server."))
        {
#else
        if (GUI.Button(new Rect(20, 40, 150, 20), "Launch Listener."))
        {
#endif
            m_transport.StartServer(m_port, 1);
            isSelected = true;
        }

        // 클라이언트를 선택했을 때 접속할 서버 주소를 입력합니다.
        m_strings = GUI.TextField(new Rect(20, 100, 200, 20), m_strings);
#if USE_TRANSPORT_TCP
        if (GUI.Button(new Rect(20, 70, 150, 20), "Connect to server"))
        {
#else
        if (GUI.Button(new Rect(20, 70, 150, 20), "Connect to terminal"))
        {
#endif
            m_transport.Connect(m_strings, m_port);
            isSelected = true;
            m_strings  = "";
        }
    }

    void OnGUIServer()
    {
#if USE_TRANSPORT_TCP
        if (GUI.Button(new Rect(20, 60, 150, 20), "Stop server"))
        {
#else
        if (GUI.Button(new Rect(20, 60, 150, 20), "Stop Listener"))
        {
#endif
            m_transport.StopServer();
            isSelected = false;
            m_strings  = "";
        }
    }

    void OnGUIClient()
    {
        // 클라이언트를 선택했을 때 접속할 서버의 주소를 입력합니다.
        if (GUI.Button(new Rect(20, 70, 150, 20), "Send message"))
        {
            byte[] buffer = System.Text.Encoding.UTF8.GetBytes("Hellow, this is client.");
            m_transport.Send(buffer, buffer.Length);
        }

        if (GUI.Button(new Rect(20, 100, 150, 20), "Disconnect"))
        {
            m_transport.Disconnect();
            isSelected = false;
            m_strings  = "";
        }
    }
}
예제 #9
0
 public void DisconnectIP()
 {
     transportTCP.Disconnect();
 }
예제 #10
0
 private void OnDestroy()
 {
     Debug.Log("socket Disconnect");
     socket.Disconnect();
 }