不会从网络流中读取繁体中文字符 [英] Traditional Chinese characters aren’t being read from network stream

查看:84
本文介绍了不会从网络流中读取繁体中文字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在应用程序中面临着这种独特的情况.我在服务器上安装了Windows Service,并以24/7运行.该服务器基本上是在异地侦听服务器端口.接收到的数据将是英文字符和繁体中文的混合.我将从非现场服务器收到的数据写到db表和文件中.

问题是传统汉字没有被读取,因为它们必须被读取.英文字符读得很好.

我正在使用以下代码

TcpClient clientSocket
NetworkStream networkStream = clientSocket.GetStream();

byte []个字节=新的byte [clientSocket.ReceiveBufferSize +1];
networkStream.Read(bytes,0,clientSocket.ReceiveBufferSize);

字符串clientdata = Encoding.GetEncoding(1252).GetString(bytes);

此clientdata包含从非现场服务器发送的接收的字符串.除汉字外,此数据与我的数据不同.

我已经尝试过同时使用Big5和1252编码.

任何帮助都是好的.

谢谢
Balaji V

Hi Guys,

I am facing this unique situation in my Application. I am having a Windows Service installed and running 24/7 on my server. This server basically listens to a server port offsite. The data received will be a mix of English characters and Traditional Chinese. I write the data received from the Offsite Server to a db table and file.

The issue is that the traditional Chinese characters aren’t being read as they have to be read. English characters are read perfectly.

I am using the following code

TcpClient clientSocket
NetworkStream networkStream = clientSocket.GetStream();

byte[] bytes = new byte[clientSocket.ReceiveBufferSize + 1];
networkStream.Read(bytes, 0, clientSocket.ReceiveBufferSize);

string clientdata = Encoding.GetEncoding(1252).GetString(bytes);

This clientdata contains the received string sent from the Offsite Server. This data is not as I excepted for Chinese characters.

I have tried using both Big5 and 1252 encoding.

Any help would be good.

Thanks
Balaji V

推荐答案

发送数据时,必须使用与非现场服务器"所用的相同编码.尝试与该产品的开发人员联系,这比尝试所有可能的编码要容易.
You have to use the same encoding as was used by the "Offsite Server" when sending the data. Try to contact the developers of that product, that''s easier than trying all possible encodings.


不!不要使用Big5或1252..NET可以使用Unicode.好吧,您可以在两者之间使用任何东西,但是当您显示文本,将其写入文件等时,应该仅使用Unicode.至于1252编码,它仅支持拉丁语,不支持中文.

顺便说一句,我非常确定您的所有角色都可以通过通讯正常传输.

预Unicode时代已经结束,正视它.

—SA
No! Don''t use Big5 or 1252. .NET works with Unicode. Well, you could use anything in between, but when you present the text, write it to file, etc., you should only use Unicode. As to the 1252 encoding, it only support Latin, not Chinese.

By the way, I''m pretty much sure all your characters are transmitted through the communications just fine.

Pre-Unicode era has finished, just face it.

—SA


这篇关于不会从网络流中读取繁体中文字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆