本文整理汇总了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));
}
}
示例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;
}
示例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));
}
}
示例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));
}
}
示例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);
}
}
示例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));
}
}*/
}
}