COnlyServerDlg::COnlyServerDlg(CWnd* pParent /*=NULL*/)
: CDialog(COnlyServerDlg::IDD, pParent),iTCP(1),iUDP(2)
{
//{{AFX_DATA_INIT(COnlyServerDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//
run_cancelled = 0; /* 指示何时按下了取消按钮 */
running = FALSE; /* 程序的运行状态 */
iProto = 1; /* 缺省为 TCP Shout */
iPortNo = SOCK_SHOUT;
blocking_option = 0L; /* 阻塞模式的全局标识 */
len = 1024;
}
/////////////////////////////////
// TODO: Add extra initialization here
WORD wMajorVersion, wMinorVersion;
wMajorVersion = MAJOR_VERSION;
wMinorVersion = MINOR_VERSION;
WORD VersionReqd;
VersionReqd=WSA_MAKEWORD(wMajorVersion, wMinorVersion);
WSADATA wsadata;
int ret;
ret = WSAStartup(VersionReqd, &wsadata);
if (ret != 0){
wshout_err ( WSAGetLastError(), "WSAStartup()");
}
return TRUE; // return TRUE unless you set the focus to a control
//////////////////////////////////
void COnlyServerDlg::OnOK()
{
// TODO: Add extra validation here
long lret;
run_cancelled = FALSE;
/* 不能重入 */
if (running)
{
MessageBox("Shout is already running !",
"Shout", MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION);
return ;
}
ClearBoxes();
running = TRUE;
//作为服务器
sd = GetSocketAndBind( iPortNo);
if (sd == SOCKET_ERROR) {
running = FALSE;
return ;
}
/* Set the I/O mode of the socket */
if (blocking_option) {
lret = 1L; /* 非阻塞模式 */
ioctlsocket(sd, FIONBIO, (u_long FAR *) &lret);
}
else {
lret = 0L; /* 阻塞模式 */
ioctlsocket(sd, FIONBIO, (u_long FAR *) &lret);
}
/* LISTEN */
//作为服务器
if (iProto == iTCP)
lret = TReadData(sd, len);
else /* UDP */
lret = UReadData(sd, len);
closesocket(sd);
running = FALSE;//. 43 .
return ;
//CDialog::OnOK();
}
/////////////////////////////////
void COnlyServerDlg::OnCancel()
{
// TODO: Add extra cleanup here
if (running) {
/* 停止 */
int ret = WSACancelBlockingCall();
run_cancelled = TRUE;
if (ret == SOCKET_ERROR) {
/* WSANOTINITIALISED or WSAENETDOWN or WSAEINVAL */
if (h_errno == WSAENETDOWN) {
/* Watch out for hAcceptSock! */
/* close what is left of the connection */
closesocket(sd);
}
}
}
return;
//CDialog::OnCancel();
}
///////////////////////////////
void COnlyServerDlg::OnExit()
{
int ret = WSACleanup();
if (ret == SOCKET_ERROR && h_errno == WSAEINPROGRESS){
MessageBox(
"Data transfer in progress.\nStop transfer first.",
"WndProc()", MB_OK | MB_APPLMODAL|MB_ICONINFORMATION);
return; /* 一个套接口正处于阻塞状态 */
}
//_free((char NEAR *) lpmyWSAData);
EndDialog(TRUE) ; /* 退出 */
}
////////////////////////////////
COnlyServerDlg::COnlyServerDlg
最新推荐文章于 2025-08-22 13:26:47 发布