'C#/problemsC#'에 해당되는 글 1건

  1. 2023.11.03 Unity C# Socket 한글 깨짐

Unity C# Socket 한글 깨짐

C#/problemsC# 2023. 11. 3. 12:14


    private void ReceiveData()
    {
        byte[] buffer = new byte[1024];
        while (isRunning)
        {
            int bytesRead = this.socketClient.GetStream().Read(buffer, 0, buffer.Length);
            if (bytesRead > 0)
            {
                byte[] receivedData = new byte[bytesRead];
                Array.Copy(buffer, receivedData, bytesRead);
                Debug.Log("Received Binary Data: " + BitConverter.ToString(receivedData));

                // 바이너리 데이터를 문자열로 변환하여 확인 (주의: 한글 문자열이 깨져있을 수 있음)
                string decodedString = Encoding.GetEncoding(949).GetString(receivedData);

                print(decodedString);
                ProcessReceivedMessage(decodedString);
            }
        }
    }

바이너리 값으로 받아서 949 or UTF-8 방식으로 직접 변환

: