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

📄 shiyan1dlg.cpp

📁 网络传输方面的范例程序,其中有MD5加密和解密的子程序,可以参考
💻 CPP
字号:
// shiyan1Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "shiyan1.h"
#include "shiyan1Dlg.h"
#include "yanzheng.h"
#include "MD5.h"
#include "kkk.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//#define  SOCKET_BUFFER_MAX_LENGTH 8000;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShiyan1Dlg dialog

CShiyan1Dlg::CShiyan1Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CShiyan1Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CShiyan1Dlg)
		// 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);
}

void CShiyan1Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CShiyan1Dlg)
	DDX_Control(pDX, IDC_STATIC1, m_static1);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CShiyan1Dlg, CDialog)
	//{{AFX_MSG_MAP(CShiyan1Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShiyan1Dlg message handlers

BOOL CShiyan1Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CShiyan1Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 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 CShiyan1Dlg::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 CShiyan1Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CShiyan1Dlg::OnOK() 
{
	// TODO: Add extra validation here
	//CSocket s1;
	//s1.Bind(s1,100);
 /*  CFileDialog t(true);
   t.DoModal();  
  t.GetPathName();
  //CFile t;
  CString  pFileName =t.GetPathName();
  CFile f( pFileName, CFile::modeCreate | CFile::modeWrite );

  CFileException e;
if( !f.Open( pFileName, CFile::modeCreate | CFile::modeWrite, &e ) )
   {
#ifdef _DEBUG
   afxDump << "File could not be opened " << e.m_cause << "\n";
#endif
   }*/
      
		
	//	sockRecv.Send(data, dw);
	//	dwRead+=dw;     
 // strSendMsg[SOCKET_BUFFER_MAX_LENGTH]=0;

/*  while((k=read(source,buf,sizeof(buf)))>0) 
   write(ns,buf,k); 
  printf("\n\n\t\t传输完毕!!!\n"); 
  close(ns); */

  
          
	const SOCKET_BUFFER_MAX_LENGTH = 8000;
      //int SOCKET_BUFFER_MAX_LENGTH;
	  //SOCKET_BUFFER_MAX_LENGTH=8000;
	WSADATA wsaData;
	WSAStartup( MAKEWORD(2,2) , &wsaData );
	//输入服务器地址
	char strServerIP[32];
	strcpy((char*)strServerIP,"25.20.183.175");


	char strSendMsg[SOCKET_BUFFER_MAX_LENGTH+1] = { 0 };

     //UINT dw=f.Read(strSendMsg, SOCKET_BUFFER_MAX_LENGTH);



     //xie





	unsigned short SERVER_PORT;
	SERVER_PORT=188;
	//将服务器网络地址转换成sockaddr_in格式
	sockaddr_in ServerAddr;
    //ServerAddr.sin_addr.S_un.S_addr.=25.20.183.176;



	ServerAddr.sin_addr.S_un.S_addr = inet_addr( (char*)strServerIP );
	ServerAddr.sin_family = AF_INET;
	
	ServerAddr.sin_port = ntohs( SERVER_PORT );
	
	SOCKET SockClient = socket( AF_INET , SOCK_STREAM , IPPROTO_TCP );
	connect( SockClient , (SOCKADDR*)&ServerAddr , sizeof(ServerAddr) );
	printf( "连接到服务器 %s : %d......连接成功\n" , inet_ntoa(ServerAddr.sin_addr) , SERVER_PORT );
  /////// char sname[20]="xht";

 







        char sname[10];
   yanzheng ty;
int mu=0;
CString cishu;  
 int user=9;
          for(int i=0;i<3;i++)
		  {
			 mu=mu+1;
			 if(ty.DoModal()==IDOK)
		  {	

           strncpy(sname,ty.m_userID,strlen(ty.m_userID));
		   sname[strlen(ty.m_userID)]='\0';
		   CString u;
		   u.Format("u is %s",sname);
		   MessageBox(u);
			 
		 }

        send(SockClient,(char*)&sname,strlen(sname)+1,0);
 
  
       recv(SockClient,(char*)&user,4,0);
       if(user==1)
	   {
		   if(mu==3)
            cishu.Format("错误登陆3次!窗口关闭");
		   else
			cishu.Format("非法用户,请重新登陆!还可登陆%d次",3-mu);
	     MessageBox(cishu);
	
	   }
	   else
		   break;

		  
	 }
		  if(mu!=3||mu==3&&user==0)
		  {



   int suiji=9;
   recv(SockClient,(char*)&suiji,4,0);
   CString s21;
   s21.Format("%d",suiji);
   MessageBox(s21);




kkk m;  
 char input1[100];
 char input2[100];
 CString stn;
 
if(m.DoModal()==IDOK)
{
	

	
	  strncpy(input1,m.m_xinxi,strlen(m.m_xinxi));
		   input1[strlen(m.m_xinxi)]='\0';
		   CString u;
		   u.Format("u is %s,chuangdu%d",input1,strlen(input1)+1);
		   MessageBox(u);

	stn.Format("%d",suiji);
	m.m_xinxi=m.m_xinxi+stn;
	strncpy(input2,m.m_xinxi,strlen(m.m_xinxi));
		   input2[strlen(m.m_xinxi)]='\0';
		   u.Format("u2 is %s,chuangdu%d",input2,strlen(input2)+1);
		   MessageBox(u);
}

 send(SockClient,input1,strlen(input1)+1,0);


unsigned char digest[16]; 
//////memset(digest,'0',16);
  CMD5 yangMD5;
yangMD5.Digest_data((unsigned char*)input2,16,digest);
///////////////////////////////////////////////////////////digest[16]='\0';


 send(SockClient,(char*)digest,16,0);

CString syt;
syt.Format("%s",digest);
//MessageBox(syt);
 //send(SockClient,(char*)&sname,strlen(sname)+1,0);
 int jieguo=9;
   recv(SockClient,(char*)&jieguo,4,0);
   if(jieguo==0)
   {
	   MessageBox("通过验证!");
   }
	
  



  
	/*int iSendCount = send(SockClient,"Iamaboy",strlen("Iamaboy")+1,0);
    s.Format("已将数据发送到服务器,共 %d 字节.\n" , iSendCount );
   // printf( "\t已将数据发送到服务器,共 %d 字节.\n" , iSendCount );
MessageBox(s); */




	//发送数据
	strSendMsg[SOCKET_BUFFER_MAX_LENGTH]=0;/**/
		 
/*	 memset(strSendMsg,0,sizeof(SOCKET_BUFFER_MAX_LENGTH));
	
	WIN32_FIND_DATA             FindFileData;
	UINT dwRead=0;
	while(dwRead<f.GetLength())
	{
	
		UINT dw=f.Read(strSendMsg, SOCKET_BUFFER_MAX_LENGTH);
	  send( SockClient , strSendMsg , strlen(strSendMsg) , 0 );
		dwRead+=dw;
	}
*/
//////////////////////////	int iSendCount = send( SockClient , strSendMsg , strlen(strSendMsg) , 0 );
/////////////////////////	printf( "\t已将数据发送到服务器,共 %d 字节.\n" , iSendCount );
	//关闭套接字
	//	f.Close();
		  }
		closesocket( SockClient );
	//清除网络库连接

	WSACleanup();

 	CDialog::OnOK();

}

void CShiyan1Dlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

⌨️ 快捷键说明

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