Home > Software engineering >  Want to receive the data from the socket recv, want to separate data, respectively in different edit
Want to receive the data from the socket recv, want to separate data, respectively in different edit

Time:10-02

Looked at other people's code, want to change, the old error when receiving data,
what to do?
Code:
 UINT recv_thd (LPVOID p) 
{
Int res;
Char MSG [1024].
CString s;
=(CCFileDlg *) AfxGetApp CCFileDlg * DLG () - & gt; GetMainWnd ();
DLG - & gt; The update (" in THD ");

While (1)
{
If ((res=recv (sock, MSG, 1024, 0))==1)
{
DLG - & gt; The update (" lost connection ");
break;
}
The else
{
MSG (res)='\ 0';
//MSG (res)=0;
DLG - & gt; The update (" server: "+ cstrings (MSG));
////////////////////////////////////////////add//
Cstrings data;
Data=https://bbs.csdn.net/topics/msg;
Cstrings str1;
Cstrings str2;
Cstrings str3;
Cstrings str4;
Cstrings str5;
Cstrings machine_num;

AfxExtractSubString (machine_num, data, 0, '#');
AfxExtractSubString (str1, data, 1, '#');
AfxExtractSubString (str2, data, 2, '#');
AfxExtractSubString (str3, data, and 3, '#');
AfxExtractSubString (str4, data, 4, '#');
AfxExtractSubString (str5, data, 5, '#');
If (machine_num=="m1")
{
DLG - & gt; M1_zhuansu=str1;
DLG - & gt; M1_qiansheng=str2;
DLG - & gt; M1_niandu=str3;
DLG - & gt; M1_dingchang=str4;
DLG - & gt; M1_chanliang=str5;
}
DLG - & gt; The UpdateData (false);

}
}

//closesocket (sock);
return 0;
}

CodePudding user response:

Use the A2T (), A2W () function transformation

CodePudding user response:

Threads want to send a message to display window, do not call directly

CodePudding user response:

PostMessage way to send data to the main thread, and only the main thread can be used to update the UI

CodePudding user response:

The
reference 3 floor oyljerry response:
PostMessage way to send data to the main thread, only the main thread can be used to update the UI interface
how this implementation

CodePudding user response:

http://blog.csdn.net/a8082649/article/details/7824927

CodePudding user response:

You send a custom message to the UI thread thread, in the message response function of the UI thread to break up the information, and then display in different edit box.

CodePudding user response:

There must be a string split agreement...

CodePudding user response:

Don't know how many predecessors in the TCP Socket
Send (many) send (less) send (wealth)
Has been so much illness recv (), recv (wealth)
Inside the trap!
http://bbs.csdn.net/topics/380167545
  • Related