如何通过winsock发送UNICODE [英] How to send UNICODE via winsock

查看:120
本文介绍了如何通过winsock发送UNICODE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

send和recv只支持char *数据类型,Winsock是否有其他函数支持UNICODE?



int WSAAPI发送(

  SOCKET     s,$
  const char * buf,

  int    ;      len,

  int        flags

);


https://docs.microsoft .com / zh-CN / windows / desktop / api / winsock2 / nf-winsock2-send


int WSAAPI recv(

  SOCKET s,

  char   * buf,

  int    len,

  int   ; 标志

);


https://docs.microsoft.com/en-us/windows/desktop/api/winsock2/nf-winsock2-recv

解决方案

send和recv是C编程遥远过去的遗留物,其中"char *"是通用缓冲类型。 它实际上仅仅意味着"指向缓冲区的指针"。 您可以发送您想要的任何字符或二进制数据。 
只需将缓冲区指针强制转换为(char *)即可发送它。


但请注意,另一端的套接字需要知道您正在发送Unicode。  它没有得到您发送的数据类型的任何指示。


The send and recv only support char* data type, does Winsock have other functions to support UNICODE ?

int WSAAPI send(
  SOCKET     s,
  const char *buf,
  int        len,
  int        flags
);

https://docs.microsoft.com/en-us/windows/desktop/api/winsock2/nf-winsock2-send

int WSAAPI recv(
  SOCKET s,
  char   *buf,
  int    len,
  int    flags
);

https://docs.microsoft.com/en-us/windows/desktop/api/winsock2/nf-winsock2-recv

解决方案

send and recv are remnants of the distant past of C programming, where "char *" was the universal buffer type.  It really just means "pointer to a buffer of bytes".  You can send whatever character or binary data you want.  Just cast the buffer pointer to (char *) to send it.

Notice, however, that the socket on the other end needs to KNOW that you're sending Unicode.  It doesn't get any indication of what data types you're sending.


这篇关于如何通过winsock发送UNICODE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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