VC ++解码来自流的变音符号

时间:2015-08-16 01:14:58

标签: c# visual-c++ character-encoding socket.io

我有一个小型应用程序客户端/服务器应用程序。客户端应用程序(C#),服务器端(VC ++)。我的应用程序将使用流将任何字符发送到服务器端;除非非英语,英语字符工作正常。 VC ++使用CString从流中接受这些数据。我修复了一些变音字符,以便在收到时正确读取但有些字符不起作用。 客户端在发送之前使用UnicodeEncoding()对此字符进行编码。它在字符É,À,È,Ù,Ê,Î,Ô,Û,Ë,Ï,Ö,Ü上工作正常,除了Ÿ(这个将在服务器端读作x_)并且土耳其字符被错误地读取

的问题:

  • 我应该在服务器端添加什么来处理变音字符,例如中文/俄文/土耳其文...等等?
  • 在客户方面;应该UnicodeEncoding()足以正确编码那些变音字符?或者其他字符的编码方式不同?

示例代码将是一个很好的帮助。

感谢。

2 个答案:

答案 0 :(得分:1)

以下代码有效。因此,数据正在被更改,或者某个地方没有刷新缓冲区。我通常建议检查字节数并查看字节数的更改位置。通常它是一个未设置为unicode的流类。

            string input = "ÉÀÈÙÂÊÎÔÛËÏÖÜŸ";
            byte[] temp = Encoding.Unicode.GetBytes(input);
            string output = Encoding.Unicode.GetString(temp);

答案 1 :(得分:0)

如果有人遇到同样的问题。

以下是我解决问题的方法。 在客户端

curl -XPUT "http://localhost:9200/againagain/" -d'
{
  "mappings": {
    "_default_": {
      "properties": {
        "service": {
          "type": "integer"
        },
        "rule": {
          "type": "integer"
        },
        "ICMP Type": {
          "type": "integer"
        },
        "ICMP Code": {
          "type": "integer"
        },
        "ip_offset": {
          "type": "integer"
        },
        "ip_id": {
          "type": "integer"
        },
        "ip_len": {
          "type": "string",
          "index": "not_analyzed"
        },
        "Confidence Level": {
          "type": "integer"
        },
        "fragments_dropped": {
          "type": "integer"
        },
        "Severity": {
          "type": "string",
          "index": "not_analyzed"
        },
        "serial_num": {
          "type": "integer"
        },
        "during_sec": {
          "type": "integer"
        },
        "Attack info": {
          "type": "string",
          "index": "not_analyzed"
        },
        "peer gateway": {
          "type": "string",
          "index": "not_analyzed"
        },
        "SmartDefense Profile": {
          "type": "string",
          "index": "not_analyzed"
        },
        "FollowUp": {
          "type": "string",
          "index": "not_analyzed"
        },
        "attack": {
          "type": "string",
          "index": "not_analyzed"
        },
        "type": {
          "type": "string",
          "index": "not_analyzed"
        },
        "Performance Impact": {
          "type": "string",
          "index": "not_analyzed"
        },
        "reject_category": {
          "type": "string",
          "index": "not_analyzed"
        },
        "action": {
          "type": "string",
          "index": "not_analyzed"
        },
        "ICMP": {
          "type": "string",
          "index": "not_analyzed"
        },
        "inzone": {
          "type": "string",
          "index": "not_analyzed"
        },
        "dn": {
          "type": "string",
          "index": "not_analyzed"
        },
        "proto": {
          "type": "string",
          "index": "not_analyzed"
        },
        "dst": {
          "type": "string",
          "index": "not_analyzed"
        },
        "message_info": {
          "type": "string",
          "index": "not_analyzed"
        },
        "rule_uid": {
          "type": "string",
          "index": "not_analyzed"
        },
        "CookieI": {
          "type": "string",
          "index": "not_analyzed"
        },
        "interface": {
          "type": "string",
          "index": "not_analyzed"
        },
        "IKE": {
          "type": "string",
          "index": "not_analyzed"
        },
        "TCP packet out of state": {
          "type": "string",
          "index": "not_analyzed"
        },
        "service_id": {
          "type": "string",
          "index": "not_analyzed"
        },
        "vpn_feature_name": {
          "type": "string",
          "index": "not_analyzed"
        },
        "Protection Type": {
          "type": "string",
          "index": "not_analyzed"
        },
        "src": {
          "type": "string",
          "index": "not_analyzed"
        },
        "fw_subproduct": {
          "type": "string",
          "index": "not_analyzed"
        },
        "protection_id": {
          "type": "string",
          "index": "not_analyzed"
        },
        "Protection Name": {
          "type": "string",
          "index": "not_analyzed"
        },
        "tcp_flags": {
          "type": "string",
          "index": "not_analyzed"
        },
        "Internal_CA": {
          "type": "string",
          "index": "not_analyzed"
        },
        "outzone": {
          "type": "string",
          "index": "not_analyzed"
        },
        "scheme": {
          "type": "string",
          "index": "not_analyzed"
        },
        "Reason": {
          "type": "string",
          "index": "not_analyzed"
        },
        "message": {
          "type": "string",
          "index": "not_analyzed"
        },
        "product": {
          "type": "string",
          "index": "not_analyzed"
        },
        "Industry Reference": {
          "type": "string",
          "index": "not_analyzed"
        }
      }
    }
  }
}'

在服务器端 使用带有CP_UTF8参数的CW2A转换字符串

if (IsUnicode(str))
{
   writer.Write((uint)str.Length + 1);
   writer.Write(Encoding.Unicode.GetBytes(str));
}

private bool IsUnicode(string text)
    {
        if (string.IsNullOrEmpty(text))
            return false;

        foreach (char c in text)
        {
            if (c > 0x7F)
                return true;
        }
        return false;
    }
相关问题