Esempio n. 1
0
    //서버에서 사용할 때.
    public NetworkController() {
        m_hostType = HostType.Server;

        GameObject nObj = GameObject.Find("Network");
        m_network = nObj.GetComponent<TransportTCP>();
        m_network.StartServer(USE_PORT, 1);
    }
Esempio n. 2
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  = "";
        }
    }
}
Esempio n. 3
0
 // Room
 public void CreateRoom()
 {
     m_transport.StartServer(m_port, 1);
     m_roomState = RoomState.JOINED;
     m_isServer  = true;
     AddMessage(ref m_messages, "[System] Created room!");
 }
Esempio n. 4
0
    //서버에서 사용할 때.
    public NetworkController()
    {
        m_hostType = HostType.Server;

        GameObject nObj = GameObject.Find("Network");

        m_network = nObj.GetComponent <TransportTCP>();
        m_network.StartServer(USE_PORT, 1);
    }
Esempio n. 5
0
    void SelectHostTypeGUI()
    {
        float sx = 800.0f;
        float sy = 600.0f;
        float px = sx * 0.5f - 100.0f;
        float py = sy * 0.75f;

        if (GUI.Button(new Rect(px, py, 200, 30), "チャットルームの作成"))
        {
            m_transport.StartServer(m_port, 1);

            m_state    = ChatState.CHATTING;
            m_isServer = true;
        }


        Rect     labelRect = new Rect(px, py + 80, 200, 30);
        GUIStyle style     = new GUIStyle();

        style.fontStyle        = FontStyle.Bold;
        style.normal.textColor = Color.white;
        GUI.Label(labelRect, "あいてのIPあどれす", style);
        labelRect.y           -= 2;
        style.fontStyle        = FontStyle.Normal;
        style.normal.textColor = Color.black;
        GUI.Label(labelRect, "あいてのIPアドレス", style);



        Rect textRect = new Rect(px, py + 100, 200, 30);

        m_hostAddress = GUI.TextField(textRect, m_hostAddress);


        if (GUI.Button(new Rect(px, py + 40, 200, 30), "チャットルームへの参加"))
        {
            //ここでIPアドレス指定
            bool ret = m_transport.Connect(m_hostAddress, m_port);
            if (ret)
            {
                m_state = ChatState.CHATTING;
            }
            else
            {
                m_state = ChatState.ERROR;
            }
        }
    }
Esempio n. 6
0
    void SelectHostTypeGUI()
    {
        float sx = 200.0f;
        float sy = 200.0f;
        float px = sx * 0.5f - 100.0f;
        float py = sy * 0.75f;

        if (GUI.Button(new Rect(px, py, 200, 30), "채팅방 만들기"))
        {
            serv = +1;
            m_transport.StartServer(m_port, 1);

            m_state    = ChatState.CHATTING;
            m_isServer = true;
        }


        Rect     labelRect = new Rect(px, py + 80, 200, 30);
        GUIStyle style     = new GUIStyle();

        style.fontStyle        = FontStyle.Bold;
        style.normal.textColor = Color.white;
        GUI.Label(labelRect, "상대방 IP 주소", style);
        labelRect.y           -= 2;
        style.fontStyle        = FontStyle.Normal;
        style.normal.textColor = Color.black;
        GUI.Label(labelRect, "상대방 IP 주소", style);

        Rect textRect = new Rect(px, py + 100, 200, 30);

        m_hostAddress = GUI.TextField(textRect, m_hostAddress);


        if (GUI.Button(new Rect(px, py + 40, 200, 30), "채팅방 들어가기"))
        {
            cli = +1;
            bool ret = m_transport.Connect(m_hostAddress, m_port);
            if (ret)
            {
                m_state = ChatState.CHATTING;
            }
            else
            {
                m_state = ChatState.ERROR;
            }
        }
    }
    public void GameStart()
    {
        m_transport.StartServer(m_port, 1);


        m_isServer = true;

        menuPanel.SetActive(false);
        gamePlayer.SetActive(true);
        rivalPlayer.SetActive(true);
        coinImage.SetActive(true);
        myScore.SetActive(true);
        rivalScore.SetActive(true);
        chattingBox.SetActive(true);

        m_state = GameState.INGAME;
        //enterText.SetActive(true);
        //enterKey.SetActive(true);
    }
Esempio n. 8
0
    // Sever 또는 Client 선택화면
    void OnUpdateSelectHost()
    {
        switch (hostType)
        {
        case HostType.Server:
        {
            bool ret = m_transport.StartServer(m_port, 1);
            m_mode = ret? Mode.Connection : Mode.Error;
        }
        break;

        case HostType.Client:
        {
            bool ret = m_transport.Connect(serverAddress, m_port);
            m_mode = ret? Mode.Connection : Mode.Error;
        }
        break;

        default:
            break;
        }
    }
Esempio n. 9
0
 public void CreateChattingRoom()
 {
     transport.StartServer(port, 1);
     state    = ChatState.CHATTING;
     isServer = true;
 }
Esempio n. 10
0
 public void StartServer()
 {
     m_transport.StartServer(m_port, 1);
 }
Esempio n. 11
0
 public void CreateServer()
 {
     transport.StartServer(25252, 1);
     byte[] buffer = System.Text.Encoding.UTF8.GetBytes("connect");
     networkObj.GetComponent <TransportTCP>().Send(buffer, buffer.Length);
 }
Esempio n. 12
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  = "";
        }
    }
}