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

📄 acceptsocket.cpp

📁 龚建斌的这本讲串口编程的书很好。很适合初学者。并附有本书的中所有例程和串口调试助手源码。
💻 CPP
字号:
// AcceptSocket.cpp : implementation file
//

#include "stdafx.h"
#include "SServer.h"
#include "AcceptSocket.h"
#include "SServerDlg.h"    //添加的主对话框类头文件

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

/////////////////////////////////////////////////////////////////////////////
// CAcceptSocket

CAcceptSocket::CAcceptSocket()
{
}

CAcceptSocket::~CAcceptSocket()
{
}


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

/////////////////////////////////////////////////////////////////////////////
// CAcceptSocket member functions


void CAcceptSocket::OnReceive(int nErrorCode) 
{
	// TODO: Add your specialized code here and/or call the base class
	char chMsg[5120], chMsgTemp[1024];
	UINT unRXCharNum;    //每次读取的字符数
	BOOL bEndFlag=0;   //接收完毕标志
	strcpy(chMsg,"");
	do
	{
		strcpy(chMsgTemp,"");
		unRXCharNum=Receive(chMsgTemp,1000);
		if(unRXCharNum>1000||unRXCharNum<=0)
		{
			AfxMessageBox("接收数据中出错",MB_OK);
			return;
		}
		else if(unRXCharNum<1000 && unRXCharNum>0)
		{
            bEndFlag=1;
		}
		chMsgTemp[unRXCharNum]=0; //加上字符串结束位
		strcat(chMsg,chMsgTemp);
	}while(bEndFlag==0);
	CSServerDlg* pDlg=(CSServerDlg*)AfxGetMainWnd(); //得到主框口(对话框)指针
	pDlg->m_strNetMsg.Format("接收到:%s",chMsg);
	pDlg->UpdateMsgData();   //在主对话的接收编辑框中显示网络端口接收到的数据
	CString strtemp;
	strtemp.Format("%s",chMsg);
	pDlg->SerialSendData(strtemp);
	strtemp="服务器已收到" + strtemp; //组成回传信息
	Send(strtemp,strtemp.GetLength(),0); //发送回传信息
 	CSocket::OnReceive(nErrorCode);
}

⌨️ 快捷键说明

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