int main(void) { #if defined (WIN32) WSADATA WSAData; int erreur = WSAStartup(MAKEWORD(2,2), &WSAData); #else int erreur = 0; #endif int i,k,j,tour=0; Obj_sock client; int port=23,pioche[104]; Paquet paq; if(!erreur) { client = create_sock_obj(); init_pioche(pioche); //127.0.0.1 est le serveur local pour tous les ordi! client=client_config(client,"127.0.0.1",port); do{ if(tour%9 == 0) tour=0; reception_pqt(client,&paq); making_pioche_b(pioche,paq);//tiens a jour ce qui reste dans la pioche du serveur printf("Nombre de tete de boeuf :%d\nN_dec =%d\n",paq.moi.tete_partie,paq.moi.n_deck); if(paq.etat==1) { printf("\nNouvelle manche!\n"); reception_pqt(client,&paq); printf("Etat du jeu :%d\n",paq.etat); init_pioche(pioche); making_pioche_b(pioche,paq); } if(paq.etat<2) { affichage_grille(paq); afficher_carte_main(paq); printf("meilleure carte :%d\n",best_card(paq,pioche,paq.nb_client,tour)); /*do{ printf("\nChoisir une carte:\n"); scanf("%d",&paq.moi.num_carte); getchar(); }while(validite_carte(paq)==-1);*/ paq.moi.num_carte= best_card(paq,pioche,paq.nb_client,tour); //paq.moi.num_carte = random_card(paq); //on supprime la carte choisie paq=supprimer_carte(paq); //Envoie le paquet modifié envoie_pqt(client,paq); sleep(1); } tour++; }while(paq.etat!=2); printf("Fin du jeu\n"); reception_pqt(client,&paq); affichage_grille(paq); /* On ferme la socket précédemment ouverte */ closesocket(client.sock); #if defined (WIN32) WSACleanup(); #endif } return EXIT_SUCCESS; }
int main(void) { signal(SIGTTOU,SIG_IGN); signal(SIGTTIN,SIG_IGN); Arc::Logger logger(Arc::Logger::rootLogger, "Test"); Arc::LogStream logcerr(std::cerr); Arc::Logger::rootLogger.addDestination(logcerr); logger.msg(Arc::INFO, "Creating client side chain"); // Create client chain Arc::XMLNode client_doc("\ <ArcConfig\ xmlns=\"http://www.nordugrid.org/schemas/ArcConfig/2007\"\ xmlns:tcp=\"http://www.nordugrid.org/schemas/ArcMCCTCP/2007\">\ <ModuleManager>\ <Path>.libs/</Path>\ <Path>../../hed/mcc/http/.libs/</Path>\ <Path>../../hed/mcc/soap/.libs/</Path>\ <Path>../../hed/mcc/tls/.libs/</Path>\ <Path>../../hed/mcc/tcp/.libs/</Path>\ <Path>../../hed/shc/.libs/</Path>\ </ModuleManager>\ <Plugins><Name>mcctcp</Name></Plugins>\ <Plugins><Name>mcctls</Name></Plugins>\ <Plugins><Name>mcchttp</Name></Plugins>\ <Plugins><Name>mccsoap</Name></Plugins>\ <Plugins><Name>arcshc</Name></Plugins>\ <Chain>\ <Component name='tcp.client' id='tcp'><tcp:Connect><tcp:Host>127.0.0.1</tcp:Host><tcp:Port>50000</tcp:Port></tcp:Connect></Component>\ <Component name='tls.client' id='tls'><next id='tcp'/>\ <!--For proxy certificate, KeyPath and CertificatePath are supposed to be the same-->\ <KeyPath>./testkey-nopass.pem</KeyPath>\ <CertificatePath>./testcert.pem</CertificatePath>\ <CACertificatePath>./testcacert.pem</CACertificatePath>\ </Component>\ <Component name='http.client' id='http'><next id='tcp'/>\ <Method>POST</Method>\ <Endpoint>/Echo</Endpoint>\ </Component>\ <Component name='soap.client' id='soap' entry='soap'>\ <next id='http'/>\ </Component>\ </Chain>\ </ArcConfig>"); Arc::Config client_config(client_doc); if(!client_config) { logger.msg(Arc::ERROR, "Failed to load client configuration"); return -1; }; Arc::MCCLoader client_loader(client_config); logger.msg(Arc::INFO, "Client side MCCs are loaded"); Arc::MCC* client_entry = client_loader["soap"]; if(!client_entry) { logger.msg(Arc::ERROR, "Client chain does not have entry point"); return -1; }; // for (int i = 0; i < 10; i++) { // Create and send echo request logger.msg(Arc::INFO, "Creating and sending request"); Arc::NS echo_ns; echo_ns["echo"]="http://www.nordugrid.org/schemas/echo"; Arc::PayloadSOAP req(echo_ns); req.NewChild("echo").NewChild("say")="HELLO"; Arc::Message reqmsg; Arc::Message repmsg; reqmsg.Payload(&req); // It is a responsibility of code initiating first Message to // provide Context and Attributes as well. Arc::MessageAttributes attributes_req; Arc::MessageAttributes attributes_rep; Arc::MessageContext context; reqmsg.Attributes(&attributes_req); reqmsg.Context(&context); repmsg.Attributes(&attributes_rep); repmsg.Context(&context); Arc::MCC_Status status = client_entry->process(reqmsg,repmsg); if(!status) { logger.msg(Arc::ERROR, "Request failed"); std::cerr << "Status: " << std::string(status) << std::endl; return -1; }; Arc::PayloadSOAP* resp = NULL; if(repmsg.Payload() == NULL) { logger.msg(Arc::ERROR, "There is no response"); return -1; }; try { resp = dynamic_cast<Arc::PayloadSOAP*>(repmsg.Payload()); } catch(std::exception&) { }; if(resp == NULL) { logger.msg(Arc::ERROR, "Response is not SOAP"); return -1; }; std::string xml; resp->GetXML(xml); std::cout << "XML: "<< xml << std::endl; std::cout << "Response: " << (std::string)((*resp)["echoResponse"]["hear"]) << std::endl; //} return 0; }
// Start sending request. void send_request(_In_ const std::shared_ptr<request_context> &request) { http_request &msg = request->m_request; auto winrt_context = std::static_pointer_cast<winrt_request_context>(request); if (!validate_method(msg.method())) { request->report_exception(http_exception(L"The method string is invalid.")); return; } if (msg.method() == http::methods::TRCE) { // Not supported by WinInet. Generate a more specific exception than what WinInet does. request->report_exception(http_exception(L"TRACE is not supported")); return; } const size_t content_length = msg._get_impl()->_get_content_length(); if (content_length == std::numeric_limits<size_t>::max()) { // IXHR2 does not allow transfer encoding chunked. So the user is expected to set the content length request->report_exception(http_exception(L"Content length is not specified in the http headers")); return; } // Start sending HTTP request. HRESULT hr = CoCreateInstance( __uuidof(FreeThreadedXMLHTTP60), nullptr, CLSCTX_INPROC, __uuidof(IXMLHTTPRequest2), reinterpret_cast<void**>(winrt_context->m_hRequest.GetAddressOf())); if (FAILED(hr)) { request->report_error(hr, L"Failure to create IXMLHTTPRequest2 instance"); return; } utility::string_t encoded_resource = http::uri_builder(m_uri).append(msg.relative_uri()).to_string(); const auto &config = client_config(); const auto &client_cred = config.credentials(); const auto &proxy = config.proxy(); const auto &proxy_cred = proxy.credentials(); if (!proxy.is_default()) { request->report_exception(http_exception(L"Only a default proxy server is supported")); return; } // New scope to ensure plain text password is cleared as soon as possible. { utility::string_t username, proxy_username; const utility::char_t *password = nullptr; const utility::char_t *proxy_password = nullptr; ::web::details::plaintext_string password_plaintext, proxy_password_plaintext; if (client_cred.is_set()) { username = client_cred.username(); password_plaintext = client_cred.decrypt(); password = password_plaintext->c_str(); } if (proxy_cred.is_set()) { proxy_username = proxy_cred.username(); proxy_password_plaintext = proxy_cred.decrypt(); proxy_password = proxy_password_plaintext->c_str(); } hr = winrt_context->m_hRequest->Open( msg.method().c_str(), encoded_resource.c_str(), Make<HttpRequestCallback>(winrt_context).Get(), username.c_str(), password, proxy_username.c_str(), proxy_password); } if (FAILED(hr)) { request->report_error(hr, L"Failure to open HTTP request"); return; } // Suppress automatic prompts for user credentials, since they are already provided. hr = winrt_context->m_hRequest->SetProperty(XHR_PROP_NO_CRED_PROMPT, TRUE); if (FAILED(hr)) { request->report_error(hr, L"Failure to set no credentials prompt property"); return; } const auto timeout = config.timeout(); const int secs = static_cast<int>(timeout.count()); hr = winrt_context->m_hRequest->SetProperty(XHR_PROP_TIMEOUT, secs * 1000); if (FAILED(hr)) { request->report_error(hr, L"Failure to set HTTP request properties"); return; } // Add headers. for (const auto &hdr : msg.headers()) { winrt_context->m_hRequest->SetRequestHeader(hdr.first.c_str(), hdr.second.c_str()); } // Set response stream. hr = winrt_context->m_hRequest->SetCustomResponseStream(Make<IResponseStream>(request).Get()); if (FAILED(hr)) { request->report_error(hr, L"Failure to set HTTP response stream"); return; } // Call the callback function of user customized options try { config.call_user_nativehandle_options(winrt_context->m_hRequest.Get()); } catch (...) { request->report_exception(std::current_exception()); return; } if (content_length == 0) { hr = winrt_context->m_hRequest->Send(nullptr, 0); } else { if ( msg.method() == http::methods::GET || msg.method() == http::methods::HEAD ) { request->report_exception(http_exception(get_with_body)); return; } hr = winrt_context->m_hRequest->Send(Make<IRequestStream>(winrt_context, content_length).Get(), content_length); } if ( FAILED(hr) ) { request->report_error(hr, L"Failure to send HTTP request"); return; } // Register for notification on cancellation to abort this request. if(msg._cancellation_token() != pplx::cancellation_token::none()) { auto requestHandle = winrt_context->m_hRequest; // cancellation callback is unregistered when request is completed. winrt_context->m_cancellationRegistration = msg._cancellation_token().register_callback([requestHandle]() { requestHandle->Abort(); }); } }