Beispiel #1
0
    // 상대의 턴일 때의 처리.
    bool DoOppnentTurn()
    {
        // 상대의 정보를 수신합니다.
        byte[] buffer   = new byte[1];
        int    recvSize = m_transport.Receive(ref buffer, buffer.Length);

        if (recvSize <= 0)
        {
            // 아직 수신되지 않았습니다.
            return(false);
        }

        // 서버라면 ○ 클라이언트라면 ×를 지정합니다.
        //Mark mark = (m_network.IsServer() == true)? Mark.Cross : Mark.Circle;

        // 수신한 정보를 선택된 칸으로 변환합니다.
        int index = (int)buffer[0];

        Debug.Log("Recv:" + index + " [" + m_transport.IsServer() + "]");

        // 칸에 둡니다.
        //bool ret = SetMarkToSpace(index, mark);
        bool ret = SetMarkToSpace(index, remoteMark);

        if (ret == false)
        {
            // 둘 수 없다.
            return(false);
        }

        return(true);
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        byte[] buffer = new byte[1400];

        int recvSize = transport.Receive(ref buffer, buffer.Length);

        if (recvSize > 0)
        {
            string message = System.Text.Encoding.UTF8.GetString(buffer);
            Debug.Log("Recv data:" + message);

            switch (message)
            {
            case "connect":
            {
                break;
            }
            }

            Debug.Log(message);
            if (networkObj.GetComponent <TransportTCP>().IsConnected() == true)
            {
                SceneManager.LoadScene("Game");
                Debug.Log("JoinGame");
            }
        }
    }
Beispiel #3
0
 // TCP로 데이터 수신하는 함수
 private void ReceiveReliableData()
 {
     byte[] packet = new byte[1400];
     while (transportTCP.Receive(ref packet, packet.Length) > 0)
     {
         // 수신패킷 분배
         ReceivePacket(packet);
     }
 }
Beispiel #4
0
    void UpdateChatting()
    {
        byte[] buffer      = new byte[1400];
        int    receiveSize = m_transport.Receive(ref buffer, buffer.Length);

        if (receiveSize > 0)
        {
            string message = System.Text.Encoding.UTF8.GetString(buffer);
            AddMessage(ref m_messages, message);
        }
    }
Beispiel #5
0
    // 가위바위보 수신 함수
    public RPSKind ReceiveRPSData()
    {
#if EMURATE_INPUT
        return(RPSKind.Rock);;           //디버그 중엔 접속한 거로 위장합니다.
#endif

        byte[] data = new byte[1024];

        // 데이터를 수신합니다.
        int recvSize = m_network.Receive(ref data, data.Length);
        if (recvSize < 0)
        {
            // 입력 정보를 수신하지 않음.
            return(RPSKind.None);
        }

        // byte 배열을 구조체로 변환합니다.
        RPSKind rps = (RPSKind)data[0];

        return(rps);
    }
Beispiel #6
0
    private void ReceiveMessage()
    {
        byte[] buffer   = new byte[1024];
        int    recvSize = socket.Receive(ref buffer, buffer.Length);

        if (recvSize > 0)
        {
            string msg = System.Text.Encoding.Default.GetString(buffer);
            Debug.Log("Recv data : " + msg + msg);
            AddMessage(msg);
        }
    }
Beispiel #7
0
    // 수신 엔드포인트
    private void UpdateChatting()
    {
        byte[] buffer = new byte[1024];

        int recvSize = socket.Receive(ref buffer, buffer.Length);

        if (recvSize > 0)
        {
            string msg = System.Text.Encoding.UTF8.GetString(buffer);
            Debug.Log("Recv data : " + msg);
            AddMessage(ref message, msg);
        }
    }
Beispiel #8
0
    void UpdateChatting()
    {
        byte[] buffer = new byte[1400];

        int recvSize = transport.Receive(ref buffer, buffer.Length);

        if (recvSize > 0)
        {
            string recvMessage = System.Text.Encoding.UTF8.GetString(buffer);
            Debug.Log("Recv data:" + recvMessage);
            chattingwindow.AddMessage(recvMessage);
        }
    }
Beispiel #9
0
 // Update is called once per frame
 void Update()
 {
     if (m_transport != null && m_transport.IsConnected() == true)
     {
         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);
         }
     }
 }
Beispiel #10
0
    void UpdateChatting()
    {
        byte[] buffer = new byte[1400];

        int recvSize = m_transport.Receive(ref buffer, buffer.Length);

        if (recvSize > 0)
        {
            string message = System.Text.Encoding.UTF8.GetString(buffer);
            Debug.Log("Recv data:" + message);
            m_chatMessage += message + "   ";            // + "\n";

            int id = (m_isServer == true)? 1 : 0;
            AddMessage(ref m_message[id], message);
        }
    }
Beispiel #11
0
    void Operation()
    {
        if (isBlack == isPlayerBlack) //自分のターンなら
        {
            if (Input.GetMouseButtonDown(0))
            {
                Vector2Int v = field.ToIndex(Input.mousePosition);
                if (!logic.Check(v.x, v.y, isBlack))
                {
                    return;
                }
                logic.SetStack(isBlack);
                isChange = true;

                byte[] buffer = new byte[2];
                buffer[0] = (byte)v.x;
                buffer[1] = (byte)v.y;

                transport.Send(buffer, buffer.Length);
            }
        }
        else//相手のターンなら
        {
            byte[] buffer = new byte[1400];

            int recvSize = transport.Receive(ref buffer, buffer.Length);
            if (recvSize > 0)
            {
                string message = System.Text.Encoding.UTF8.GetString(buffer);
                Debug.Log("Recv data:" + message);

                if (!logic.Check(buffer[0], buffer[1], isBlack))
                {
                    return;
                }

                logic.SetStack(isBlack);
                isChange = true;
            }
        }
    }
Beispiel #12
0
    void UpdateChatting()
    {
        byte[] buffer = new byte[1400];

        int recvSize = m_transport.Receive(ref buffer, buffer.Length);

        if (recvSize > 0)
        {
            string message = System.Text.Encoding.UTF8.GetString(buffer);
            Debug.Log("Recv data:" + message);
            m_chatMessage += message + "   ";            // + "\n";

            int id = (m_isServer == true)? 1 : 0;
            AddMessage(ref m_message[id], message);

            var playerData = message.Split(',');
            if (playerData.Length == 7)
            {
                int   i  = int.Parse(playerData[0]);
                float x  = float.Parse(playerData[1]);
                float y  = float.Parse(playerData[2]);
                float z  = float.Parse(playerData[3]);
                float rx = float.Parse(playerData[4]);
                float ry = float.Parse(playerData[5]);
                float rz = float.Parse(playerData[6]);
                try
                {
                    Debug.Log("transform:" + i + "," + rx + "," + ry + "," + rz);
                    Players[i].transform.position = new Vector3(x, y, z);
                    Players[i].transform.rotation = Quaternion.Euler(rx, ry, rz);
                }
                catch (Exception e2)
                {
                    Debug.Log("error:" + e2.ToString());
                }
            }
        }
    }
Beispiel #13
0
 public int Receive(ref byte[] buffer, int size)
 {
     return(m_transport.Receive(ref buffer, size));
 }
Beispiel #14
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  = "";
        }
    }
}