⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usrskt.cpp

📁 在电力行业中的应用,vxworks的应用程序,其中包括消息,信号量,和多任务调度的应用
💻 CPP
字号:
// UsrSkt.cpp : implementation file
//

#include "stdafx.h"
#include "WinClt.h"
#include "UsrSkt.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern CWinCltApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CUsrSkt

CUsrSkt::CUsrSkt()
{
}

CUsrSkt::~CUsrSkt()
{
}


// Do not edit the following lines, which are needed by ClassWizard.
#if 0
BEGIN_MESSAGE_MAP(CUsrSkt, CAsyncSocket)
	//{{AFX_MSG_MAP(CUsrSkt)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#endif	// 0

/////////////////////////////////////////////////////////////////////////////
// CUsrSkt member functions

void CUsrSkt::OnClose(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	EnableWindow(GetDlgItem(theApp.m_pMainWnd->m_hWnd,ID_UsrStart),TRUE);
	CAsyncSocket::OnClose(nErrorCode);
}

void CUsrSkt::OnReceive(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class	
	char buff[100];
	int len;
	len = Receive(buff, 100);
	buff[len]='\0';
	static int first = 1;
	char QuitMsg1[]="the server has quit!";
	char QuitMsg2[]="please restart later!";
	if(strstr(buff,MSG_NET_CHECK)!=NULL)
	{
		/*normal check net connection*/
		AsyncSelect(FD_WRITE|FD_CLOSE);
	}
	else if(strstr(buff,SERVER_QUIT)!=NULL)
	{
		SetWindowText(GetDlgItem(theApp.m_pMainWnd->m_hWnd,IDC_UsrReceive),QuitMsg1);
		SetWindowText(GetDlgItem(theApp.m_pMainWnd->m_hWnd,IDC_UsrSend),QuitMsg2);
		EnableWindow(GetDlgItem(theApp.m_pMainWnd->m_hWnd,ID_UsrSend),FALSE);
		Send(SERVER_QUIT,sizeof(SERVER_QUIT));
		Close();
		return;
 	}
	else
	{
		SetWindowText(GetDlgItem(theApp.m_pMainWnd->m_hWnd,IDC_UsrReceive),buff);
	}
	CAsyncSocket::OnReceive(nErrorCode);
}

void CUsrSkt::OnSend(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	char buff[100];
	int len;
	len = GetWindowText(GetDlgItem(theApp.m_pMainWnd->m_hWnd,IDC_UsrSend),buff,100);
	buff[len]='\0';
	Send(buff,len+1,0);
	SetWindowText(GetDlgItem(theApp.m_pMainWnd->m_hWnd,IDC_UsrSend),'\0');
	AsyncSelect(FD_READ | FD_CLOSE);
	if(strstr(buff,CLIENT_QUIT)!=NULL)
	{
		Close();
		EnableWindow(GetDlgItem(theApp.m_pMainWnd->m_hWnd,ID_UsrStart),TRUE);
		EnableWindow(GetDlgItem(theApp.m_pMainWnd->m_hWnd,ID_UsrSend),FALSE);
	}
	CAsyncSocket::OnSend(nErrorCode);
}

void CUsrSkt::OnConnect(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(nErrorCode == 0)
	{ 
		MessageBox(NULL,"Connected","onConnect",MB_OK);
		EnableWindow(GetDlgItem(theApp.m_pMainWnd->m_hWnd,ID_UsrSend),TRUE);
		SetWindowText(GetDlgItem(theApp.m_pMainWnd->m_hWnd,IDC_UsrSend),"");
		AsyncSelect(FD_READ|FD_CLOSE);
		CAsyncSocket::OnConnect(nErrorCode);
	}
	else
	{
		SetWindowText(GetDlgItem(theApp.m_pMainWnd->m_hWnd,IDC_UsrSend),"Timeout");
		Close();
		SetWindowText(GetDlgItem(theApp.m_pMainWnd->m_hWnd,IDC_UsrSend),"connect time out");
		EnableWindow(GetDlgItem(theApp.m_pMainWnd->m_hWnd,ID_UsrStart),TRUE);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -