struct sockaddr_in addr;
int addr_len = sizeof (struct sockaddr_in);
CString strstate;
Remember to use char to receive data, because the data transmitted in the network is just and encoded
Irrelevant stream of bytes
So the byte stream is received and converted to wide-character Unicode encoding for display and
Write a file
Char tempsocketreceive[maxdatalength] = "";
memset (tempsocketreceive, 0, maxdatalength);//char empty;
Tempsocketreceive[maxdatalength-1] = ' + ';//Prevent data end
There is hot and hot scalding, plus it still appears
int length = Recvfrom (Listen_socket, Tempsocketreceive,
Maxdatalength, 0, (struct sockaddr *) &addr, &addr_len);
Determine the amount of memory space required to convert multibyte encoding to wide-byte encoding
DWORD dwnum = MultiByteToWideChar (CP_ACP, 0,
Tempsocketreceive,-1, NULL, 0);
Allocate memory on the heap, the requested memory must be released, or the memory leaks in the morning
Cause the program to crash
wchar_t *pwtext;
Pwtext = new Wchar_t[dwnum];
Converts a byte-wide word to Unicode, and the result of the conversion is stored on the heap memory, remembering
Delete
MultiByteToWideChar (CP_ACP, 0, Tempsocketreceive,-1,
Pwtext, Dwnum);
The received data is expressed in CString, which facilitates display on MFC and writing with CFile
Thing
CString RawData (Pwtext);//raw serial data data without parsing
CString temp = Comdecode (rawdata);//parsed serial port data
Heap memory has been converted to stack memory by the CString constructor, so the heap memory is released early
Put
Delete[]pwtext;
VC Programming Unicode Character set convert char array to CString