網(wǎng)絡(luò)編程作業(yè)_第1頁(yè)
網(wǎng)絡(luò)編程作業(yè)_第2頁(yè)
網(wǎng)絡(luò)編程作業(yè)_第3頁(yè)
網(wǎng)絡(luò)編程作業(yè)_第4頁(yè)
網(wǎng)絡(luò)編程作業(yè)_第5頁(yè)
已閱讀5頁(yè),還剩5頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

本文格式為Word版,下載可任意編輯——網(wǎng)絡(luò)編程作業(yè)

voidCTcpclientDlg::onrev(){}

voidCTcpclientDlg::oncl(){

//Beep(2000,100);

MessageBox(\失去連接或者找不到服務(wù)器\);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(\確定退出嗎\,\請(qǐng)確定

\,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,\已設(shè)名字\+clientname+\連

接服務(wù)器成功\);

}else{

clconect.Close();

MessageBox(\連接失敗,請(qǐng)檢查IP與端口是否與服務(wù)器一致!CStringenterinfo=clientname+\進(jìn)入閑聊室\;intlen=enterinfo.GetLength();clconect.Send(enterinfo,len);

或者服務(wù)器沒開啟\,\連接錯(cuò)誤\,MB_ICONERROR);

}else{}

MessageBox(\端口或IP輸入有誤,請(qǐng)重新輸入\);}

}

voidCTcpclientDlg::Onsend(){}

CStringstr;

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

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

閑聊器客戶端運(yùn)行界面

(二)客戶端的實(shí)現(xiàn)

#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,\服務(wù)器\);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=\新用戶進(jìn)入\;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. 本站所有資源如無(wú)特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論