#include #include "afxsock.h" #include "math.h" #include #ifdef _DEBUG #define new DEBUG_NEW #endif #define Saddress "127.0.0.1" #define port 8080 //Same port as server CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; //initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, GetCommandLine(), 0)) { //TODO: change error code to suit your needs _tprintf(_T("Fatal error: MFC initialization failed\n")); nRetCode = 1; } else { //TODO: code your application's behaviour here CSocket client; AfxSocketInit(NULL); //1.Create Socket client.Create(); if (client.Connect(CA2W(Saddress), port)) { cout << "Client have connected to Server!" << endl; //Receiving from server the position number int id; client.Receive((char*)&id, sizeof(id), 0); cout << "\n\nThis is client number " << id + 1 << endl << endl; //Send first number to server //printf("Sending number 1,value %d to server\n", numbers[0]); //client.Send((char*)&numbers[0], sizeof(int), 0); cout << "\n\nhi\n\n\n"; char r_str[1000]; //Receiving returning results from server client.Receive(r_str, 10, 0); int len = atoi(r_str); client.Receive(r_str, len, 0); r_str[len] = 0; cout << "\nServer: " << r_str; /*char thongbao[100], * buff; unsigned char buff[1024]; int len = 0; len = client.Receive(buff, strlen(thongbao), 0); buff[len] = 0; cout << buff << endl;*/ client.Close(); } else { printf("Can not connect to server!"); } getchar(); client.Close(); } getchar(); return nRetCode; }