Nguoi dung nhap tu client den server Server AfxSocketInit(NULL); CSocket a,b; a.Create(12345); a.Listen(); a.Accept(b); char chuoi[20]; printf("toi day"); b.Receive(chuoi,sizeof(chuoi),0); puts(chuoi); CLIENT AfxSocketInit(NULL);(“”) CSocket ketnoi; ketnoi.Create(); if(!ketnoi.Connect("172.29.50.22",12345)) { printf("loi ket noi"); return 0; } char chuoi[20]; strcpy(chuoi,"hello server"); printf("toi day"); gets(chuoi); ketnoi.Send(chuoi,sizeof(chuoi),0); (server gui chuoi den client) SERVER AfxSocketInit(NULL); CSocket a,b; a.Create(12345); a.Listen(); a.Accept(b); char chuoi[20]; /*printf("toi day"); b.Receive(chuoi,sizeof(chuoi),0); puts(chuoi);*/ strcpy(chuoi,"hello client"); b.Send(chuoi,sizeof(chuoi),0); CLIENT AfxSocketInit(NULL);(“”) CSocket ketnoi; ketnoi.Create(); if(!ketnoi.Connect("172.29.50.22",12345)) { printf("loi ket noi"); return 0; } char chuoi[20]; /*strcpy(chuoi,"hello server");
printf("toi day"); gets(chuoi); ketnoi.Send(chuoi,sizeof(chuoi),0);*/ ketnoi.Receive(chuoi,sizeof(chuoi),0); puts(chuoi); nguoi dung nhap chuoi(tu server den client) server AfxSocketInit(NULL); CSocket a,b; a.Create(12345); a.Listen(); a.Accept(b); char chuoi[20]; /*printf("toi day"); b.Receive(chuoi,sizeof(chuoi),0); puts(chuoi);*/ //strcpy(chuoi,"hello client"); gets(chuoi); b.Send(chuoi,sizeof(chuoi),0); } client AfxSocketInit(NULL); CSocket ketnoi; ketnoi.Create(); if(!ketnoi.Connect("172.29.50.22",12345)) { printf("loi ket noi"); return 0; } char chuoi[20]; /*strcpy(chuoi,"hello server"); printf("toi day"); gets(chuoi); ketnoi.Send(chuoi,sizeof(chuoi),0);*/ ketnoi.Receive(chuoi,sizeof(chuoi),0); puts(chuoi); } return nRetCode; } nguoi dung nhap chuoi tu server gui den client, va nguoc lai server AfxSocketInit(NULL); CSocket a,b; a.Create(12345); a.Listen(); a.Accept(b); char chuoi[20]; printf("Server chat: "); gets(chuoi);
b.Send(chuoi,sizeof(chuoi),0); b.Receive(chuoi, sizeof(chuoi), 0); puts(chuoi); client AfxSocketInit(NULL); CSocket ketnoi; ketnoi.Create(); if(!ketnoi.Connect("172.29.50.22",12345)) { printf("loi ket noi"); return 0; } char chuoi[20]; ketnoi.Receive(chuoi,sizeof(chuoi),0); puts(chuoi); printf("Client chat: "); gets(chuoi); ketnoi.Send(chuoi, sizeof(chuoi), 0);