Mã:
// client.cpp : Defines the entry point for the console application.// #include "stdafx.h"#include "client.h"#include<WinSock2.h>#ifdef _DEBUG#define new DEBUG_NEW#endif // The one and only application object CWinApp theApp; struct PhanSo{ int tu; int mau;}; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]){ int nRetCode = 0; HMODULE hModule = ::GetModuleHandle(NULL); if (hModule != NULL) { // initialize MFC and print and error on failure if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs _tprintf(_T("Fatal Error: MFC initialization failed
")); nRetCode = 1; } else { // TODO: code your application's behavior here. WORD wVersionRequested; WSADATA wsaData; int err; wVersionRequested = MAKEWORD(2, 2); err = WSAStartup(wVersionRequested, &wsaData); if(err != 0) { printf("ko the khoi tao thu vien !
"); exit(-1); } // tao socket SOCKET sockClient = socket(AF_INET, SOCK_STREAM, 0); //Nhap dia chi char sAdd[1000]; printf("Nhap vao dia chi server : "); gets(sAdd); sockaddr_in serverAdd; serverAdd.sin_family = AF_INET; serverAdd.sin_port = htons(30000); serverAdd.sin_addr.S_un.S_addr = inet_addr(sAdd); // connect den server connect(sockClient, (sockaddr*) &serverAdd, sizeof(serverAdd)); //Nhap phan so PhanSo ps; printf("Nhap tu so : "); scanf("%d", &ps.tu); printf("Nhap mau so : "); scanf("%d", &ps.mau); // nhap so tu nhien int number; printf("Nhap so tu nhien : "); scanf("%d", &number); //tao socket server SOCKET sockServer = socket(AF_INET, NULL, NULL); //gui phan so send(sockServer, (char*) &ps, sizeof(PhanSo), 0); //gui so tu nhien send(sockServer, (char*) &number, sizeof(int), 0); /han ket qua tu server recv(sockServer, (char*) &ps, sizeof(PhanSo), 0); //xuat ket qua nhan dc printf("ket qua nhan duoc tu server la : %d / %d ", ps.tu, ps.mau); // shutdown(sockServer, SD_BOTH); closesocket(sockServer); closesocket(sockClient); WSACleanup(); } } else { // TODO: change error code to suit your needs _tprintf(_T("Fatal Error: GetModuleHandle failed
")); nRetCode = 1; } return nRetCode;}
Ngọc Bích xanh bản chất thuộc dòng đá đá hoa (jade). Và cẩm thạch là tên gọi chung của ngọc bích. Vì thực chất chúng thuộc dòng đá đa khoáng được hình thành từ chất Silicat dưới dạng dioxy. Ngọc bích...
Chia sẻ Vòng tay ngọc bích xanh là...