int main(int argc, char *argv[]){ if (argc < 5) { fprintf(stderr, "<host> <port> <port><port>\n"); exit (1); } myClient(argv); return 0; }
//com.yaozu.listener.playlist.provider JNIEXPORT void JNICALL Java_com_yaozu_listener_playlist_provider_NativeMediaScanner_processFile (JNIEnv *env, jobject obj, jstring path,jobject client) { if (!mMediaScanner) { mMediaScanner = new MediaScanner(); } char *cpath = Jstring2CStr(env, path); MyMediaScannerClient myClient(env,client); mMediaScanner->processFile(cpath, myClient); }
int main(int argc, char ** argv) { Screen s; Events ev(&(s.GetInput()), argv[1]); sf::Event real; Client myClient(argv[1], s.GetStruct()); myClient.Launch(); while(s.IsOpened()){ if(myClient.MGetPointeurPartieEncours()){ while(s.GetEvent(real)){ if (real.Type == sf::Event::Closed){ s.Close(); myClient.Terminate(); } } ev.Try(s.GetFrameTime()); s.Refresh(s.GetStruct()); s.Display(); } } return 0; }
int main(int argc, char **argv) { // parse command-line args bool myIpv4Only = haveOption(argc, argv, "ipv4-only"); bool myConnectToIpv4 = haveOption(argc, argv, "connect-ipv4") || myIpv4Only; bool myUseSsl = haveOption(argc, argv, "ssl"); bool myIsPerformanceTest = haveOption(argc, argv, "performance"); const std::string ipv4 = "127.0.0.1"; const std::string ipv6 = myIpv4Only? "" : "::1"; const unsigned port = 32000; std::cout << "Prepare to serve " << (myUseSsl ? "secured" : "unsecured") << " rpc requests at " << ipv4 << ":" << port; if (!myIpv4Only) { std::cout << ", " << ipv6 << ":" << port; } std::cout << std::endl; ulxr::IP myIP; myIP.ipv4 = ipv4; myIP.ipv6 = ipv6; std::auto_ptr<ulxr::HttpProtocol> mySvrProto; try { // Setup server std::auto_ptr<ulxr::TcpIpConnection> mySvrConn; if (myUseSsl) { ulxr::SSLConnection *ssl = new ulxr::SSLConnection (myIP, port, false); ssl->setCryptographyData("password", "foo-cert.pem", "foo-cert.pem"); mySvrConn.reset(ssl); } else { mySvrConn.reset(new ulxr::TcpIpConnection (myIP, port)); } mySvrConn->setTcpNoDelay(true); mySvrProto.reset(new ulxr::HttpProtocol(mySvrConn.get())); unsigned int myNumProc = 1; ulxr::MultiProcessRpcServer server(mySvrProto.get(), myNumProc); TestWorker worker; server.addMethod(ulxr::make_method(worker, &TestWorker::echo), ulxr::Signature(ulxr::Struct()), "echo", ulxr::Signature() << ulxr::Integer() << ulxr::Boolean() << ulxr::Double() << ulxr::DateTime() << ulxr::DateTime() << ulxr::RpcString() << ulxr::Base64() << ulxr::Array() << ulxr::Struct()); server.start(); mysleep(500); // wait for the service to start timeval startTick, endTick; gettimeofday(&startTick, NULL); const ExecTime myExpectedExecTime(1000, 5000, 10000); const size_t myNumCalls = myIsPerformanceTest ? myExpectedExecTime.numCalls : 1; std::cout << "Prepare to request " << (myUseSsl ? "secured" : "unsecured") << " communication to " << (myConnectToIpv4 ? ipv4 : ipv6) << ":" << port << std::endl; std::auto_ptr<ulxr::TcpIpConnection> myClientConn; if (myUseSsl) myClientConn.reset(new ulxr::SSLConnection (myConnectToIpv4 ? ipv4 : ipv6, port, false)); else myClientConn.reset(new ulxr::TcpIpConnection (myConnectToIpv4 ? ipv4 : ipv6, port)); myClientConn->setTcpNoDelay(true); ulxr::HttpProtocol myClientProto(myClientConn.get()); ulxr::Requester myClient(&myClientProto); for (size_t iCall = 0; iCall < myNumCalls; ++iCall) { callEcho(myClient); } if (myIsPerformanceTest) { gettimeofday(&endTick, NULL); long secs = endTick.tv_sec - startTick.tv_sec; long usecs = endTick.tv_usec - startTick.tv_usec; double elapsed = (double)secs * 1000; elapsed += (double)usecs/(double)1000; std::cout << "Finished. Elapsed Time for " << myNumCalls << " calls: " << (int)elapsed << " msec\n"; TEST_ASSERT((int)elapsed < myExpectedExecTime.get(myUseSsl)); } } catch(ulxr::Exception &ex) { std::cerr << "Error occurred: " << ex.why() << std::endl; return 1; } catch(std::exception &ex) { std::cerr << "Error occurred: " << ex.what() << std::endl; return 1; } catch(...) { std::cerr << "unknown Error occured.\n"; return 1; } return 0; }
int main() { // Initialize the winsock library MyTcpSocket::initialize(); // get client's information (assume neither the name nor the address is given) winLog << endl; winLog << "Retrieve the localHost [CLIENT] name and address:" << endl; winLog.flush(); //以下是客户端程序,所有服务器IP从配置文件中读取 //********************************************************************************* // 【①】 客户端HostInfo(hostent) MyHostInfo clientInfo; string clientName = clientInfo.getHostName(); string clientIPAddress = clientInfo.getHostIPAddress(); cout << "Name: " << clientName << endl; cout << "Address: " << clientIPAddress << endl; winLog << " ==> Name: " << clientName << endl; winLog << " ==> Address: " << clientIPAddress << endl; //********************************************************************************* // get server's IP address and name 【服务器IP,从配置文件读取】 string serverIPAddress = ""; readServerConfig(serverIPAddress); winLog << endl; winLog << "Retrieve the remoteHost [SERVER] name and address:" << endl; winLog << " ==> the given address is " << serverIPAddress << endl; // 【②】 服务器端HostInfo(hostent) MyHostInfo serverInfo(serverIPAddress,ADDRESS); string serverName = serverInfo.getHostName(); cout << "Name: " << serverName << endl; cout << "Address: " << serverIPAddress << endl; winLog << " ==> Name: " << serverName << endl; winLog << " ==> Address: " << serverIPAddress << endl; //********************************************************************************* // create the socket for client MyTcpSocket myClient(PORTNUM); cout << myClient; winLog << "client configuation: " << endl; winLog << myClient; //********************************************************************************* // connect to the server. cout << "connecting to the server [" << serverName << "] ... " << endl; winLog << "connecting to the server [" << serverName << "] ... " << endl; myClient.connectToServer(serverIPAddress,ADDRESS); int recvBytes = 0; while (1) { // send message to server char messageToServer[MAX_MSG_LEN+1]; memset(messageToServer,0,sizeof(messageToServer)); cout << "[SEND] "; cin.getline(messageToServer,MAX_MSG_LEN); winLog << "[SEND] " << messageToServer << endl; myClient.sendMessage(string(messageToServer)); if ( !string(messageToServer).compare("Quit") || !string(messageToServer).compare("quit") ) break; // receive message from server string messageFromServer = ""; recvBytes = myClient.recieveMessage(messageFromServer); if ( recvBytes == -99 ) break; cout << "[RECV:" << serverName << "]: " << messageFromServer << endl; winLog << "[RECV:" << serverName << "]: " << messageFromServer << endl; } return EXIT_SUCCESS; }