.Close();
m_bConnected = FALSE;
GetDlgItem(IDC_BUTTON_CONNECT)->EnableWindow(!m_bConnected);
GetDlgItem(IDC_BUTTON_DISCONNECT)->EnableWindow(m_bConnected);
}
void CCommSocketDlg::OnButtonSend()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
int nRet = m_wskClient.SendData(m_strEditSendData, m_strEditSendData.GetLength(), 3);
if(nRet <= 0)
{
CString info;
info.Format("发送失败:%d", m_wskClient.err);
AfxMessageBox(info);
}
else
{
TRACE("Begin Read\n");
char buf[256];
int nRet = m_wskClient.ReadData(buf, 255, 3);
if(nRet > 0)
{
buf[nRet] = 0;
m_strEditRecvData.Format("%.255s\r\n", buf);
GetDlgItem(IDC_EDIT_RECVDATA)->SetWindowText(m_strEditRecvData);
}
}
}
void CALLBACK Listen(SOCKET s, int ServerPort, const char *ClientIP)
{
CString info;
CString strtmp;
strtmp.Format("连接上%s:%d socket=0x%X\r\n", ClientIP, ServerPort, s);
theApp.m_pMainWnd->GetDlgItem(IDC_EDIT_SERVERDATA)->GetWindowText(info);
info += strtmp;
theApp.m_pMainWnd->GetDlgItem(IDC_EDIT_SERVERDATA)->SetWindowText(info);
((CEdit*)(theApp.m_pMainWnd->GetDlgItem(IDC_EDIT_SERVERDATA)))->LineScroll(999999);
int nRet;
char buf[256];
CWSocket wsk;
wsk = s;
while(1)
{
info.Empty();
nRet = wsk.ReadData(buf, 250, 60);
if(nRet > 0)
{
buf[nRet] = 0;
TRACE("recv: %s\n", buf);
strtmp.Format("s%X recv: %.255s\r\n", s, buf);
//theApp.m_pMainWnd->GetDlgItem(IDC_SERVERDATA)->GetWindowText(info);
//TRACE("GetWindowText\n");
info += strtmp;
//theApp.m_pMainWnd->GetDlgItem(IDC
上一篇:
CommSocket.cpp
下一篇:
宽量程高精度电池数据采集系统的研究