当前位置: 首页>>代码示例>>C++>>正文


C++ socket_ptr::write_some方法代码示例

本文整理汇总了C++中socket_ptr::write_some方法的典型用法代码示例。如果您正苦于以下问题:C++ socket_ptr::write_some方法的具体用法?C++ socket_ptr::write_some怎么用?C++ socket_ptr::write_some使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在socket_ptr的用法示例。


在下文中一共展示了socket_ptr::write_some方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: writeLoop

void writeLoop(socket_ptr sock, string_ptr prompt)
{
    char inputBuf[inputSize] = {0};

    for(;;)
    {
        //cin.getline(inputBuf, inputSize);
        //inputMsg = *prompt + (string)inputBuf + '\n';
	mainMutex.lock();
	
	
        if(!sendMessage.empty())
        {
		sendMessage = *prompt + sendMessage;
		cout << sendMessage << sendMessage.empty() << endl;
            //sock->write_some(buffer(inputMsg, inputSize));
		sock->write_some(buffer(sendMessage, inputSize));
        }

        if(sendMessage.find("exit") != string::npos){
            mainMutex.unlock();
		exit(1);
	}
        sendMessage.clear();
	memset(inputBuf,0,inputSize);
	mainMutex.unlock();
	boost::this_thread::sleep( boost::posix_time::millisec(500));
    }
}
开发者ID:kasimsuzen,项目名称:CSE395-Project-1,代码行数:29,代码来源:client.cpp

示例2: clientCube

int clientCube()
{
    try
    {
        boost::thread_group threads;

        string_ptr prompt( buildPrompt() );
        promptCpy = prompt;

        sock->connect(ep);

        cerr << "Server connected." << endl;

        string inputMsg = *prompt + "yes";
        sock->write_some(buffer(inputMsg, inputSize));

        threads.create_thread(boost::bind(displayLoop, sock));
        threads.create_thread(boost::bind(inboundLoop, sock, prompt));
        threads.create_thread(boost::bind(writeLoop, sock, prompt));
    }
    catch(std::exception& e)
    {
        cerr << e.what() << endl;
        __serverStatus = 0;
        return -1;
    }
    __serverStatus = 1;
    return 1;
}
开发者ID:kasimsuzen,项目名称:CSE395-Project-1,代码行数:29,代码来源:network.cpp

示例3: writeLoop

void writeLoop(socket_ptr sock, string_ptr prompt)
{
    string inputMsg;
    int i = 1;
    for(;;)
    {
        inputMsg = *prompt;

        mainMutex.lock();
        if(!sendMessage.empty())
        {
            cerr << "Message sent:" << sendMessage <<":\n";
            inputMsg += sendMessage;
            sock->write_some(buffer(inputMsg, inputSize));
            //sendMessage.clear();
            if(i==10)
            {
                sendMessage.clear();
                i=1;
            }else
                ++i;

        }
        mainMutex.unlock();
        if(inputMsg.find("exit") != string::npos)
            return;
        inputMsg.clear();
        boost::this_thread::sleep( boost::posix_time::millisec(1000));
    }
}
开发者ID:kasimsuzen,项目名称:CSE395-Project-1,代码行数:30,代码来源:network.cpp

示例4: writeLoop

void Client::writeLoop(socket_ptr sock, string_ptr prompt) {
    
    char inBuf[sizeInput]; memset( inBuf, 0, sizeof(inBuf));
    string strMsg;
    
    while( true){
        cin.getline( inBuf, sizeInput);
        strMsg = *prompt + (string)inBuf + "\n";
        
        if( !strMsg.empty() ){
            sock->write_some( buffer(inBuf, sizeInput) );
        }
        if(strMsg.find("exit") != string::npos)
            exit(1);
        strMsg = "";
        memset( inBuf, 0, sizeof(inBuf));
    }
}
开发者ID:fengzhyuan,项目名称:INET,代码行数:18,代码来源:chatClient.cpp

示例5: writeLoop

void writeLoop(socket_ptr sock, string_ptr prompt)
{
    char inputBuf[inputSize] = {0};
    string inputMsg;

    for(;;)
    {
        cin.getline(inputBuf, inputSize);
        inputMsg = *prompt + (string)inputBuf + '\n';

        if(!inputMsg.empty())
        {
            sock->write_some(buffer(inputMsg, inputSize));
        }

        if(inputMsg.find("exit") != string::npos)
            exit(1);

        inputMsg.clear();
        memset(inputBuf, 0, inputSize);
    }
}
开发者ID:ivankoval,项目名称:ChatApp,代码行数:22,代码来源:clientChat.cpp

示例6: writeLoop

void writeLoop(socket_ptr sock, string_ptr prompt)
{
//    char inputBuf[inputSize] = {0};
//    string inputMsg;
//    
//    for(;;)
//    {
//        cin.getline(inputBuf, inputSize);
//        inputMsg = *prompt + (string)inputBuf + '\n';
//        
//        if(!inputMsg.empty())
//        {
//            sock->write_some(buffer(inputMsg, inputSize));
//        }
//        
//        if(inputMsg.find("exit") != string::npos)
//            exit(1);
//        
//        inputMsg.clear();
//        memset(inputBuf, 0, inputSize);
//    }
    size_t messageCount = messageList.size();
    srand((unsigned int)time(NULL));
    for (;;){
        int number = rand() % 3 + 1;
        if (number == 1)
        {
        /*if (!sock->is_open())
        {
        sock.reset(new tcp::socket(service));
        sock->connect(ep);
        }*/        
        string temp = "msg";
        sock->write_some(buffer(temp + *prompt + messageList[rand() % messageCount]));
        boost::this_thread::sleep( boost::posix_time::millisec(1000));
        }
        else if (number == 2)
        {
        /*if (!sock->is_open())
        {
        sock.reset(new tcp::socket(service));
        sock->connect(ep);
        } */       
        string temp = "job";
        temp += *prompt + " ";
        int length = (rand() % 4 + 1) * 100;        
        int jobID =  rand() % 1000 + 1;
        int priority = rand() % 100 + 1;
        temp += std::to_string(jobID) + " ";
        temp += std::to_string(length) + " ";
        temp += std::to_string(priority) + " ";
        cout << "Job Create: " << " JobId: " << std::to_string(jobID) << " Job Priority: " << std::to_string(priority) << " Job length: " << std::to_string(priority) << endl;
        sock->write_some(buffer(temp));
        boost::this_thread::sleep( boost::posix_time::millisec(1000));
        }
        /*else
        {
        if (sock->is_open())
        {            
        sock->write_some(buffer("exit"));
        boost::this_thread::sleep( boost::posix_time::millisec(1000));
        }
        }*/
    }
}
开发者ID:hanchen999,项目名称:OS94,代码行数:65,代码来源:client.cpp


注:本文中的socket_ptr::write_some方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。