Home > Software engineering >  Under the Unicode cannot obtain recv, returns an empty
Under the Unicode cannot obtain recv, returns an empty

Time:10-07

Cstrings GetMode (SOCKET sock, SOCKADDR_IN address, WSAEVENT eventLink)
{
Cstrings ats, recv;
Char * data;
Char recvbuf [50]={0};
SOCKADDR_IN recvaddr;
Int nbSize, nSize=sizeof (recvaddr), iError;
The at=_T (" at + MODEL=? \ r \ n ");
Data=(LPSTR https://bbs.csdn.net/topics/LPCTSTR) at;
Sendto (sock, data, palawan GetLength (), 0, (SOCKADDR *) & amp; Address, sizeof (SOCKADDR_IN));
IError=WSAWaitForMultipleEvents (1, & amp; EventLink, FALSE, 1000, FALSE);//1 seconds waiting for the return value
WSAResetEvent (eventLink);//reset event to no signal state
If (iError==WSA_WAIT_FAILED | | iError==WSA_WAIT_TIMEOUT)
Return _T (" ");//return directly
If ((nbSize=recvfrom (sock, recvbuf, sizeof (recvbuf), 0, (the SOCKADDR FAR *) & amp; Recvaddr, & amp; NSize))==SOCKET_ERROR)
Return _T (" ");
Recv. The Format (_T (" % d "), recvbuf [7] 0 x30);
Return the recv;
}

CodePudding user response:

You deal with the data socket is done with char array, and then their transform coding format, etc

CodePudding user response:

Computer memory or file content or transport it is just a one-dimensional binary byte array and its corresponding binary address;
The human brain to a computer memory or file contents or transfer the content of the one-dimensional binary byte array and its corresponding binary address some parts as an integer, number of signed/unsigned number, floating point Numbers, complex Numbers, letters, digits, Chinese/Korean/French... Character/string, assembly instructions, functions, function parameters, heap, stack, arrays, Pointers, array pointer and pointer array, the array of arrays, pointer to pointer, two-dimensional arrays, character lattice, the coordinates of character strokes, black and white binary images and grayscale images, color images, audio, video, fingerprint information, id information...

CodePudding user response:

The at=_T (" at + MODEL=? \ r \ n ");

Content must be converted to the type char

CodePudding user response:

Cstrings===& gt; CStringA

CodePudding user response:

For ANSI and Unicode USES a lot of people always use and when to use when not to himself is not clear, such as you, you send content, if stubbornly to distinguish the ANSI and Unicode, that is two different sets of data flow, have the corresponding processing your server side? And send data tell the server that is a Unicode? If you have to do these, you can freely, however, cstrings Unicode version of GetLength () always returns the number of characters, rather than the number of bytes, even if your server side support Unicode, you sending data is incomplete, Windows programming, using _T or TEXT is a good habit, but it mostly for Windows platform for internal use, but when necessary, such as Windows API has two sets of, some parameters or data structure requirements must be ANSI or Unicode, must be or like to cross-platform, such as network transmission, in this case, some data format is usually fixed ANSI or Unicode first, explicitly specify char or WCHAR is a must, but cannot use _T, TEXT and TCHAR,

CodePudding user response:

Network data transmission with UNICODE, ANSI it doesn't matter, all is a byte stream way transmission.

CodePudding user response:

With above, this is certainly can, always bit rate of network transmission

CodePudding user response:

Really just don't look at the document you write code,
Sendto specifies the number of bytes rather than number of characters
When the words you do not use utf16 less done will also be sent at the end of the '\ 0'
  • Related