在高人的指点下,学习了客户端的编写,主要是socket的网络编程和线程的使用
使用的vs mfc编写的,有很多没有必要的代码,现在把主要的代码写上来
客户端的代码:
void CclientDlg::OnBnClickedOk()
{
CString strText;
m_Edit.GetWindowText(strText);
m_Edit.SetWindowText(_T(" "));
//发送
char c_buffer[256];
memset(c_buffer,0,sizeof(c_buffer));
WideCharToMultiByte(CP_ACP, 0, strText.GetBuffer(), strText.GetLength(), c_buffer, sizeof(c_buffer)-1, NULL, FALSE);
//strcpy(c_buffer, strText.GetBuffer());
if(SOCKET_ERROR == send(c_socket,(char*)(c_buffer),strlen(c_buffer),0))
{
AfxMessageBox(_T("发送失败"));
exit(-1);
}
m_Edit.SetFocus();
}
void CclientDlg::OnBnClickedButton1()
{
WSADATA wsaData;
WORD socketVersion = MAKEWORD(2, 2);
if (::WSAStartup(socketVersion, &wsaData) != 0)
{
AfxMessageBox(_T("Init winsock2 error\n"));
exit(-1);
}
/