Esempio n. 1
0
    // UDP 연결 요청
    // FIX THIS : 지금은 그저 Connect결과가 true면 성공으로 간주.(200122)
    public void ConnectIP()
    {
        if (!isNetConnected)
        {
            //Debug.Log("UDP 연결 버튼 클릭됨.");
            //SetNetConnectionStatus(transportUDP.Connect("127.0.0.1", 3098));
            //if (GetNetConnectionStatus())
            //    Time.timeScale = 1f;

            // 로컬 테스트라면, 127.0.0.1 로컬호스트에 연결
            if (isLocalTest)
            {
                SetNetConnectionStatus(transportTCP.Connect("127.0.0.1", 3098));
            }
            // 로컬테스트가 아니라면, 다른 아이피에 연결
            else
            {
                Debug.Log("gameserver");
                SetNetConnectionStatus(transportTCP.Connect(Info.IP, 1000));
            }
            //transportTCP.Send(System.Text.Encoding.UTF8.GetBytes("PLEASEE"), 10);
            if (GetNetConnectionStatus())
            {
                Time.timeScale = 1f;
            }
        }
    }
    public void JoinGame()
    {
        try
        {
            m_hostAddress = enterIp.text;
            Debug.Log(m_hostAddress);
        }
        catch (NullReferenceException ex)
        {
            Debug.Log("myLight was not set in the inspector");
        }


        bool ret = m_transport.Connect(m_hostAddress, m_port);

        if (ret)
        {
            m_state = GameState.INGAME;
        }
        else
        {
            m_state = GameState.ERROR;
        }

        menuPanel.SetActive(false);
        gamePlayer.SetActive(true);
        rivalPlayer.SetActive(true);
        coinImage.SetActive(true);
        myScore.SetActive(true);
        rivalScore.SetActive(true);
        chattingBox.SetActive(true);
        //enterText.SetActive(true);
        //enterKey.SetActive(true);
    }
Esempio n. 3
0
    //클라이언트에서 사용할 때.
    public NetworkController(string serverAddress) {
        m_hostType = HostType.Client;

        GameObject nObj = GameObject.Find("Network");
		m_network = nObj.GetComponent<TransportTCP>();
        m_network.Connect(serverAddress, USE_PORT);
    }
Esempio n. 4
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. 5
0
 // Start is called before the first frame update
 void Start()
 {
     // 서버에 접속
     socket.Connect(address, port);
     // 통신 스레드 시작. Thread를 쓸 것이냐, Coroutine을 쓸 것이냐 선택해야함. 스레드는 일시정지 불가
     //socket.LaunceThread();
 }
Esempio n. 6
0
    public void CreateClient()
    {
        transport.Connect(textBox.GetComponent <Text>().text, 25252);
        Debug.Log("connectadd" + textBox.GetComponent <Text>().text);

        byte[] buffer = System.Text.Encoding.UTF8.GetBytes("connect");
        networkObj.GetComponent <TransportTCP>().Send(buffer, buffer.Length);
    }
Esempio n. 7
0
    //클라이언트에서 사용할 때.
    public NetworkController(string serverAddress)
    {
        m_hostType = HostType.Client;

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

        m_network = nObj.GetComponent <TransportTCP>();
        m_network.Connect(serverAddress, USE_PORT);
    }
Esempio n. 8
0
    void Start()
    {
        httpManager = new HTTPManager();
        userInfo    = GameObject.Find("DataObject").GetComponent <UserInfo>();
        socket      = GetComponent <TransportTCP>();
        Debug.Log("유저 : " + userInfo.userData.token);
        socket.Connect(address, port);

        // StartCoroutine(ChatTest());
    }
Esempio n. 9
0
    public void JoinRoom()
    {
        bool ret = m_transport.Connect(m_hostAddress, m_port);

        if (!ret)
        {
            m_roomState = RoomState.ERROR;
            return;
        }
        m_roomState = RoomState.JOINED;
    }
Esempio n. 10
0
 // FIX THIS : 지금은 그저 Connect결과가 true면 성공으로 간주.(200122)
 public void ConnectIP()
 {
     if (!isNetConnected)
     {
         SetNetConnectionStatus(transportTCP.Connect(Info.IP, 3098));
         if (GetNetConnectionStatus())
         {
             Time.timeScale = 1f;
         }
     }
 }
Esempio n. 11
0
    public void ConnetChattingRoom()
    {
        bool ret = transport.Connect(hostAddress.text, port);

        if (ret)
        {
            state = ChatState.CHATTING;
        }
        else
        {
            state = ChatState.ERROR;
        }
    }
Esempio n. 12
0
    public bool Connect(string hostAddress)
    {
        bool success = m_transport.Connect(hostAddress, m_port);

        // 접속을 알립니다.
        if (m_handler != null)
        {
            NetEventState state = new NetEventState();
            state.type   = NetEventType.Connect;
            state.result = NetEventResult.Success;
            m_handler(state);
        }

        return(success);
    }
Esempio n. 13
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. 14
0
        void SelectHostTypeGUI()
        {
            //서버IP지정
            m_hostAddress = "172.30.78.96";


            //채팅방무조건 들어가기
            if (true)
            {
                bool ret = m_transport.Connect(m_hostAddress, m_port);
                if (ret)
                {
                    m_state = ChatState.CHATTING;
                }
            }
        }
Esempio n. 15
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;
            }
        }
    }
Esempio n. 16
0
    // Start is called before the first frame update
    void Start()
    {
        address = "127.0.0.1";

        /*
         * socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         * socket.NoDelay = true;
         * socket.SendBufferSize = 0;
         * socket.Connect(address, port);
         */

        mysocket.Connect(address, port);
        //mysocket.LaunceThread();
        byte[] buffer = System.Text.Encoding.UTF8.GetBytes("hello, this is client");
        mysocket.Send(buffer, buffer.Length);

        //socket.Send(buffer, buffer.Length, SocketFlags.None);
    }
Esempio n. 17
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. 18
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  = "";
        }
    }
}