网络编程作业_第1页
网络编程作业_第2页
网络编程作业_第3页
网络编程作业_第4页
网络编程作业_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

本文格式为Word版,下载可任意编辑——网络编程作业

voidCTcpclientDlg::onrev(){}

voidCTcpclientDlg::oncl(){

//Beep(2000,100);

MessageBox(\失去连接或者找不到服务器\);CStringstr,str1;charss[100];

for(intj=0;jLineScroll(ce->GetLineCount()-1);;

str.Format(\,ss);

CWnd*cw=GetDlgItem(IDC_EDIT1);

cw->EnableWindow(true);cw=GetDlgItem(IDC_EDIT2);cw->EnableWindow(true);cw=GetDlgItem(IDC_connet);cw->EnableWindow(true);cw=GetDlgItem(IDC_EDIT5);cw->EnableWindow(true);

}

voidCTcpclientDlg::OnClose(){

intconfirm=MessageBox(\确定退出吗\,\请确定

\,MB_YESNO|MB_ICONQUESTION);}

voidCTcpclientDlg::OnOK(){};

voidCTcpclientDlg::Onconnet(){

//TODO:Addyourcontrolnotificationhandlercodehereif(clconect)clconect.Close();CStringipstr,portstr;intport;

GetDlgItemText(IDC_EDIT1,ipstr);GetDlgItemText(IDC_EDIT2,portstr);GetDlgItemText(IDC_EDIT5,clientname);portstr.TrimLeft();portstr.TrimRight();

CTcpclientDlg::Onsend();if(confirm==IDYES){}

CStringenterinfo=clientname+\退出了闲聊室\;intlen=enterinfo.GetLength();clconect.Send(enterinfo,len);CDialog::OnClose();

port=atoi(portstr);

if(port>0//

cslisten.Bind(port);

if(clconect.Connect(ipstr,port)){

clconect.setp(this);

CWnd*cw=GetDlgItem(IDC_EDIT1);cw->EnableWindow(false);cw=GetDlgItem(IDC_EDIT2);cw->EnableWindow(false);cw=GetDlgItem(IDC_connet);cw->EnableWindow(false);cw=GetDlgItem(IDC_EDIT5);cw->EnableWindow(false);

SetDlgItemText(IDC_EDIT3,\已设名字\+clientname+\连

接服务器成功\);

}else{

clconect.Close();

MessageBox(\连接失败,请检查IP与端口是否与服务器一致!CStringenterinfo=clientname+\进入闲聊室\;intlen=enterinfo.GetLength();clconect.Send(enterinfo,len);

或者服务器没开启\,\连接错误\,MB_ICONERROR);

}else{}

MessageBox(\端口或IP输入有误,请重新输入\);}

}

voidCTcpclientDlg::Onsend(){}

CStringstr;

GetDlgItemText(IDC_EDIT4,str);str=clientname+\+str;intlen=str.GetLength();

if(clconect.Send(str,len)>1)SetDlgItemText(IDC_EDIT4,\);

闲聊器客户端运行界面

(二)客户端的实现

#include\#include\#include\

#ifdef_DEBUG

#definenewDEBUG_NEW#undefTHIS_FILE

staticcharTHIS_FILE[]=__FILE__;#endif

csocketcslisten,csrev[20];intcsnum=0;charname[20][100];CStringsevername;

//CAboutDlgdialogusedforAppAbout

classCAboutDlg:publicCDialog{public:CAboutDlg();//DialogData

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

//ClassWizardgeneratedvirtualfunctionoverrides

//{{AFX_VIRTUAL(CAboutDlg)

protected:

virtualvoidDoDataExchange(CDataExchange*pDX);support//}}AFX_VIRTUAL

//Implementation

protected://{{AFX_MSG(CAboutDlg)//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

//DDX/DDV

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

voidCAboutDlg::DoDataExchange(CDataExchange*pDX){}

BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)//{{AFX_MSG_MAP(CAboutDlg)//Nomessagehandlers//}}AFX_MSG_MAPEND_MESSAGE_MAP()//CTcpseverDlgdialog

CTcpseverDlg::CTcpseverDlg(CWnd*pParent/*=NULL*/):CDialog(CTcpseverDlg::IDD,pParent){}

voidCTcpseverDlg::DoDataExchange(CDataExchange*pDX){

CDialog::DoDataExchange(pDX);//{{AFX_DATA_INIT(CTcpseverDlg)//}}AFX_DATA_INIT

//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CAboutDlg)//}}AFX_DATA_MAP

//{{AFX_DATA_INIT(CAboutDlg)//}}AFX_DATA_INIT

}

//{{AFX_DATA_MAP(CTcpseverDlg)//}}AFX_DATA_MAP

BEGIN_MESSAGE_MAP(CTcpseverDlg,CDialog)//{{AFX_MSG_MAP(CTcpseverDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()

ON_WM_QUERYDRAGICON()ON_WM_CLOSE()

ON_BN_CLICKED(IDC_listen,Onlisten)ON_BN_CLICKED(IDC_send,Onsend)//}}AFX_MSG_MAP

END_MESSAGE_MAP()

//CTcpseverDlgmessagehandlersBOOLCTcpseverDlg::OnInitDialog(){

CDialog::OnInitDialog();

//Add\

//IDM_ABOUTBOXmustbeinthesystemcommandrange.ASSERT((IDM_ABOUTBOXASSERT(IDM_ABOUTBOXAppendMenu(MF_SEPARATOR);

pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,

strAboutMenu);}

voidCTcpseverDlg::OnSysCommand(UINTnID,LPARAMlParam){}

//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,//thisisautomaticallydoneforyoubytheframework.

if((nIDCAboutDlgdlgAbout;dlgAbout.DoModal();

}

//Settheiconforthisdialog.Theframeworkdoesthisautomatically//whentheapplication'smainwindowisnotadialogSetIcon(m_hIcon,TRUE);

//Setbigicon

}

SetIcon(m_hIcon,FALSE);

//Setsmallicon

//TODO:AddextrainitializationhereSetDlgItemText(IDC_EDIT3,\服务器\);SetDlgItemText(IDC_EDIT4,\);

SetDlgItemText(IDC_EDIT2,\欢迎来到闲聊室!!\);

returnTRUE;//returnTRUEunlessyousetthefocustoacontrol

voidCTcpseverDlg::OnPaint(){

if(IsIconic()){

CPaintDCdc(this);//devicecontextforpainting

SendMessage(WM_ICONERASEBKGND,(WPARAM)

dc.GetSafeHdc(),0);}

//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags//theminimizedwindow.

HCURSORCTcpseverDlg::OnQueryDragIcon(){}

return(HCURSOR)m_hIcon;}else{}

CDialog::OnPaint();

//Centericoninclientrectangle

intcxIcon=GetSystemMetrics(SM_CXICON);intcyIcon=GetSystemMetrics(SM_CYICON);CRectrect;

GetClientRect(

intx=(rect.Width()-cxIcon+1)/2;inty=(rect.Height()-cyIcon+1)/2;

//Drawtheicon

dc.DrawIcon(x,y,m_hIcon);

voidCTcpseverDlg::onrev(intmynum){}

voidCTcpseverDlg::onac(){}

voidCTcpseverDlg::oncl(){

//Beep(2000,100);CStringstr1,str;

GetDlgItemText(IDC_EDIT1,str1);CStringstr2=\新用户进入\;str=str1+str2;

SetDlgItemText(IDC_EDIT1,str);

cslisten.Accept(csrev[++csnum]);csrev[csnum].setp(this,csnum);CStringstr,str1;inti;charss[100];

for(intj=0;jLineScroll(ce->GetLineCount()-1);;

}

//Beep(2000,100);

for(inti=1;i0

cslisten.Listen();cslisten.setp(this,csnum);cslisten.Listen();

CWnd*cw=GetDlgItem(IDC_EDIT3);cw->EnableWindow(false);cw=GetDlgItem(IDC_EDIT4);cw->EnableWindow(false);cw=GetDlgItem(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论