📄 nunetdemdlg.cpp
字号:
/* */
/* This function starts and stops the Winsock TCP server thread. */
/* */
/****************************************************************************/
void CNuNetDemDlg::OnTcpserve()
{
// TCP Server
CTCPCLISTR dlg;
HWND hwnd = GetSafeHwnd();
if (m_bTCPServeStatus)
{
m_bTCPServeStatus = FALSE;
ToggleButtons(TRUE);
testvalue=0;
// Tell the Thread to shut down the Target TCP Client
SetEvent(m_pTSThread->m_hEventKill);
}
else
{
m_bTCPServeStatus = TRUE;
m_ListCtrl.DeleteAllItems();
InitList();
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
testvalue = 2;
ToggleButtons(FALSE);
ResetEvent(m_pTSThread->m_hEventKill);
}
else
ToggleButtons(TRUE);
}
}
/****************************************************************************/
/* FUNCTION */
/* */
/* CNuNetDemDlg::OnUdpclient */
/* */
/* DESCRIPTION */
/* */
/* This function starts and stops the Winsock UDP client thread. */
/* */
/****************************************************************************/
void CNuNetDemDlg::OnUdpclient()
{
// UDP Client
UDPSERVSTR dlg1;
AskIpaddr dlg2;
CUDPCLI dlg;
HWND hwnd = GetSafeHwnd();
if (m_bUDPClientStatus)
{
m_bUDPClientStatus = FALSE;
ToggleButtons(TRUE);
testvalue=0;
// Tell the Thread to shut down
SetEvent(m_pUCThread->m_hEventKill);
}
else
{
m_ListCtrl.DeleteAllItems();
InitList();
dlg2.m_IPAddress = m_IPAddress;
int nResponse = dlg2.DoModal();
if (nResponse == IDOK)
{
m_IPAddress = dlg2.m_IPAddress;
nResponse = dlg1.DoModal();
if (nResponse = IDOK)
{
dlg.m_num_trans1 = m_num_trans1;
dlg.m_size_bytes1 = m_size_bytes1;
nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
m_num_trans1 = dlg.m_num_trans1;
m_size_bytes1 = dlg.m_size_bytes1;
m_bUDPClientStatus = TRUE;
ToggleButtons(FALSE);
testvalue=3;
// Create and Start the Tread
m_pUCThread = new CUdpClientThread(this);
m_pUCThread->CreateThread();
}
else
ToggleButtons(TRUE);
}
else
ToggleButtons(TRUE);
}
else
ToggleButtons(TRUE);
}
}
/****************************************************************************/
/* FUNCTION */
/* */
/* CNuNetDemDlg::OnUdpserver */
/* */
/* DESCRIPTION */
/* */
/* This function starts and stops the Winsock UDP server thread. */
/* */
/****************************************************************************/
void CNuNetDemDlg::OnUdpserver()
{
// UDP Server
UDPCLISTR dlg;
HWND hwnd = GetSafeHwnd();
if (m_bUDPServeStatus)
{
m_bUDPServeStatus = FALSE;
testvalue= 0;
ToggleButtons(TRUE);
Sleep(10);
// Tell the Thread to shut down
SetEvent(m_pUSThread->m_hEventKill);
}
else
{
m_bUDPServeStatus = TRUE;
m_ListCtrl.DeleteAllItems();
InitList();
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
testvalue = 4;
ToggleButtons(FALSE);
ResetEvent(m_pUSThread->m_hEventKill);
}
else
ToggleButtons(TRUE);
}
}
/****************************************************************************/
/* FUNCTION */
/* */
/* CNuNetDemDlg::OnCancel */
/* */
/* DESCRIPTION */
/* */
/* Function handles when the Close button has been clicked. */
/* */
/****************************************************************************/
void CNuNetDemDlg::OnCancel()
{
CDialog::OnCancel();
}
/****************************************************************************/
/* FUNCTION */
/* */
/* CNuNetDemDlg::ResetSocket */
/* */
/* DESCRIPTION */
/* */
/* Resets the Socket when necessary. */
/* */
/****************************************************************************/
void CNuNetDemDlg::ResetSocket(void)
{
LINGER lingerInfo;
WSADATA stWSAData; /* return data for Winsock startup */
int nRet; /* startup return error value */
int socketd;
lingerInfo.l_onoff = 1;
lingerInfo.l_linger = 0;
nRet = WSAStartup(0x0101, &stWSAData);
socketd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
setsockopt( socketd,SOL_SOCKET, SO_LINGER, (char*)&lingerInfo, sizeof(lingerInfo) );
// Only use closesocket, no shutdown()
nRet = closesocket(socketd);
if (nRet != 0)
{
//printf("Problem closing socket! Error - %d\n", WSAGetLastError());
AfxMessageBox("Problem closing socket!");
}
// De-register WinSock
WSACleanup();
}
/****************************************************************************/
/* FUNCTION */
/* */
/* CNuNetDemDlg::OnHelp */
/* */
/* DESCRIPTION */
/* */
/* This function calls the helpfile associted with this program. */
/* */
/****************************************************************************/
void CNuNetDemDlg::OnHelp()
{
// TODO: Add your control notification handler code here
//AfxMessageBox(" Refer to the Specific Net Port Notes for help on running your embedded applications.");
AfxGetApp()->WinHelp(0, HELP_FINDER);
}
/****************************************************************************/
/* FUNCTION */
/* */
/* CNuNetDemDlg::ToggleButtons */
/* */
/* DESCRIPTION */
/* */
/* This function is used to deactivate/reactivate buttons during different */
/* sequences of the test. */
/* */
/****************************************************************************/
void CNuNetDemDlg::ToggleButtons(BOOL On)
{
if (On)
{
m_StopButton.EnableWindow(FALSE);
m_btTcpServe.EnableWindow(TRUE);
m_btTcpServe.SetCheck(0);
m_btTcpClient.EnableWindow(TRUE);
m_btTcpClient.SetCheck(0);
m_btUdpServe.EnableWindow(TRUE);
m_btUdpServe.SetCheck(0);
m_btUdpClient.EnableWindow(TRUE);
m_btUdpClient.SetCheck(0);
}
else
{
m_StopButton.EnableWindow(TRUE);
m_btTcpServe.EnableWindow(FALSE);
m_btTcpClient.EnableWindow(FALSE);
m_btUdpServe.EnableWindow(FALSE);
m_btUdpClient.EnableWindow(FALSE);
}
}
/****************************************************************************/
/* FUNCTION */
/* */
/* CNuNetDemDlg::Onbutton2 */
/* */
/* DESCRIPTION */
/* */
/* This function is used when the Stop test button is pressed to halt the */
/* the test thread that is being executed. */
/* */
/****************************************************************************/
void CNuNetDemDlg::OnButton2()
{
// TODO: Add your control notification handler code here
switch(testvalue)
{
case 1:
OnTcpclient();
break;
case 2:
OnTcpserve();
break;
case 3:
OnUdpclient();
break;
case 4:
OnUdpserver();
break;
default:
break;
}
}
/****************************************************************************/
/* FUNCTION */
/* */
/* CNuNetDemDlg::UpdateList */
/* */
/* DESCRIPTION */
/* */
/* This function updates the list (embedded transfer Edit window). */
/* */
/****************************************************************************/
void CNuNetDemDlg::UpdateList(char *buffer, unsigned long packet, unsigned long bytes)
{
CString temp;
temp.Format("%lu", packet);
m_ListCtrl.InsertItem(m_index, temp, 0);
temp.Format("%lu", bytes);
m_ListCtrl.SetItemText(m_index, 1, temp);
m_ListCtrl.SetItemText(m_index, 2, buffer);
m_ListCtrl.EnsureVisible(m_index,0);
m_index++;
if (m_index > 2000)
{
m_ListCtrl.DeleteItem(0);
m_index--;
}
}
/****************************************************************************/
/* FUNCTION */
/* */
/* CNuNetDemDlg::InitList */
/* */
/* DESCRIPTION */
/* */
/* This function initializes the List controls for the Embedded Transfer */
/* Status Information. */
/* */
/****************************************************************************/
void CNuNetDemDlg::InitList()
{
//Initialize list control
m_index = 0;
LV_COLUMN ColumnInfo;
char *ColumnLabels[] = {"Packet Number", "Bytes", "Data Buffer"}; /* Column header labels*/
int ColumnWidth[] = {100, 50, 5000};
int index;
/* Column header attributes */
ColumnInfo.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM | LVIF_IMAGE;
ColumnInfo.fmt = LVCFMT_LEFT; // left align column
ColumnInfo.cx = 5000; // width of column in pixels
/* Construct the column headers */
for (index=0; index<3; index++)
{
ColumnInfo.cx = ColumnWidth[index];
ColumnInfo.iSubItem = index;
ColumnInfo.pszText = ColumnLabels[index];
m_ListCtrl.InsertColumn(index, &ColumnInfo);
}
}
/****************************************************************************/
/* FUNCTION */
/* */
/* CNuNetDemDlg::OnUpdateStatus5() */
/* */
/* DESCRIPTION */
/* */
/* routine Used to remove errors. */
/* */
/****************************************************************************/
void CNuNetDemDlg::OnVscrollStatus5()
{
// TODO: Add your control notification handler code here
}
/****************************************************************************/
/* FUNCTION */
/* */
/* CNuNetDemDlg::OnUpdateStatus5() */
/* */
/* DESCRIPTION */
/* */
/* routine Used to remove errors. */
/* */
/****************************************************************************/
void CNuNetDemDlg::OnUpdateStatus5()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_UPDATE flag ORed into the lParam mask.
// TODO: Add your control notification handler code here
}
/****************************************************************************/
/* FUNCTION */
/* */
/* CNuNetDemDlg:: OnChangeStatus5() */
/* */
/* DESCRIPTION */
/* */
/* routine Used to remove errors. */
/* */
/****************************************************************************/
void CNuNetDemDlg::OnChangeStatus5()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_CHANGE flag ORed into the lParam mask.
// TODO: Add your control notification handler code here
}
/****************************************************************************/
/* FUNCTION */
/* */
/* CNuNetDemDlg::OnMaxtextStatus5 */
/* */
/* DESCRIPTION */
/* */
/* routine Used to remove errors. */
/* */
/****************************************************************************/
void CNuNetDemDlg::OnMaxtextStatus5()
{
// TODO: Add your control notification handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -