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

📄 63_s1_clientdlg.cpp

📁 dsp下网络通信实验,很有用哦.平台为DSP54
💻 CPP
字号:
// 63_s1_clientDlg.cpp : implementation file
//

#include "stdafx.h"
#include "63_s1_client.h"
#include "63_s1_clientDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMy63_s1_clientDlg dialog

CMy63_s1_clientDlg::CMy63_s1_clientDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMy63_s1_clientDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMy63_s1_clientDlg)
	m_szRecv = _T("");
	m_size = 0;
	m_ip = _T("");
	m_strSendData = _T("");
	m_sDspIP = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMy63_s1_clientDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMy63_s1_clientDlg)
	DDX_Control(pDX, btnRcvData, m_btnRcvData);
	DDX_Text(pDX, IDC_EDIT1, m_szRecv);
	DDX_Text(pDX, IDC_EDIT2, m_size);
	DDX_Text(pDX, editSendData, m_strSendData);
	DDX_Text(pDX, IDC_EDIT3, m_sDspIP);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMy63_s1_clientDlg, CDialog)
	//{{AFX_MSG_MAP(CMy63_s1_clientDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_BN_CLICKED(btnSendData, OnbtnSendData)
	ON_BN_CLICKED(btnRcvData, OnbtnRcvData)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy63_s1_clientDlg message handlers

BOOL CMy63_s1_clientDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	m_sockRecv.Create(0x1201,SOCK_DGRAM,NULL);
	m_sockRecv.Bind(0x1201,NULL);
	m_sockSend.Create(0x1200,SOCK_DGRAM,NULL);
	m_sockSend.Bind(0x1200,"127.0.0.1");

	//m_sockRecv.Create();
	//BOOL fC=m_sockRecv.Connect("127.0.0.1",6802);
	//TRACE("connect is %s\n",(fC)?"OK":"Error");
	//SetTimer(1,10,NULL);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMy63_s1_clientDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMy63_s1_clientDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
int can=0x1234abcd;
void CMy63_s1_clientDlg::OnTimer(UINT nIDEvent) 
{
	char szRecv[300];	
	//CString szIP("192.168.123.170");
	
	UINT uPort=0x1200;
	int iRecv=m_sockRecv.ReceiveFrom(szRecv,300,m_sDspIP,uPort,0);
	TRACE("received %d byte\n",iRecv);	
	
	if(iRecv>=0)
	{
		int i;

		for (i = 0; i < 6; i++) {
			szRecv[i] = 'a';
		}
		szRecv[iRecv]='\0';
		m_szRecv=szRecv;
		m_size=iRecv;
		UpdateData(FALSE);
	}
	CDialog::OnTimer(nIDEvent);
}

void CMy63_s1_clientDlg::OnbtnSendData() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	m_sockSend.SendTo(m_strSendData.GetBuffer(100),m_strSendData.GetLength(),0x1201,"192.168.123.170");
}

void CMy63_s1_clientDlg::OnbtnRcvData() 
{
	// TODO: Add your control notification handler code here
	CString str;
	UpdateData(TRUE);
	m_btnRcvData.GetWindowText(str);
	if(str.GetAt(0) == 'R'){
		SetTimer(1,10,NULL);
		m_btnRcvData.SetWindowText("stop rcv data");
	}else{
		KillTimer(1);
		m_btnRcvData.SetWindowText("Rcv Data");
	}	
}

⌨️ 快捷键说明

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