socket 发送和接收 编码问题。

frdking 2013-11-27 02:05:04
byte[] bf;
bf = Encoding.Default.GetBytes("成功!!!,.;");
newSocket.Send(bf);

这个用Default发送,接收端也用Default来接收。但是只显示成功。 后面的!!!,.; 这些符号没显示。 UTF8 ASCII Unicode 都试过不行,请问用什么编码能显示出符号啊?
...全文
372 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
rtdb 2013-11-27
  • 打赏
  • 举报
回复
UTF8是国际标准,基本上所有的字符集都可以。 你的接收代码呢?
全栈极简 2013-11-27
  • 打赏
  • 举报
回复
接收端:
UdpClient client = new UdpClient(7901);
IPEndPoint ep = null;
byte[] data = client.Receive(ref ep);
string data_receive = Encoding.UTF8.GetString(data);
Console.WriteLine(data_receive);

发送端:
 UdpClient client = new UdpClient();
IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7901);
byte[] bytes = Encoding.UTF8.GetBytes("成功!!!,.;");
client.Send(bytes, bytes.Length, ep);

效果:
frdking 2013-11-27
  • 打赏
  • 举报
回复
引用 1 楼 rtdb 的回复:
发送和接收都使用UTF8就肯定可以了
我用的是VS2012 UTF8不行。。
rtdb 2013-11-27
  • 打赏
  • 举报
回复
发送和接收都使用UTF8就肯定可以了

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧