本文整理汇总了C++中server::send方法的典型用法代码示例。如果您正苦于以下问题:C++ server::send方法的具体用法?C++ server::send怎么用?C++ server::send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类server
的用法示例。
在下文中一共展示了server::send方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: send_msg
void _test_websocket_server::send_msg(const test_websocket_msg& msg)
{
// Wait for the websocket server to be initialized.
pplx::task<void>(m_server_connected).wait();
const auto& data = msg.data();
auto flags = websocketpp::frame::opcode::close;
switch (msg.msg_type())
{
case test_websocket_message_type::WEB_SOCKET_UTF8_MESSAGE_TYPE:
flags = websocketpp::frame::opcode::text; // WebSocket::FRAME_FLAG_FIN | WebSocket::FRAME_OP_TEXT;
break;
case test_websocket_message_type::WEB_SOCKET_BINARY_MESSAGE_TYPE:
flags = websocketpp::frame::opcode::binary; // WebSocket::FRAME_FLAG_FIN | WebSocket::FRAME_OP_BINARY;
break;
case test_websocket_message_type::WEB_SOCKET_CLOSE_TYPE:
flags = websocketpp::frame::opcode::close; // WebSocket::FRAME_OP_CLOSE;
break;
case test_websocket_message_type::WEB_SOCKET_UTF8_FRAGMENT_TYPE:
case test_websocket_message_type::WEB_SOCKET_BINARY_FRAGMENT_TYPE:
default:
throw std::runtime_error("invalid message type");
}
std::string strmsg(data.begin(), data.end());
if (msg.msg_type() == test_websocket_message_type::WEB_SOCKET_CLOSE_TYPE)
{
close(strmsg);
}
else
{
// std::cerr << "Sending message from server: " << strmsg << std::endl;
m_srv.send(m_con, strmsg, flags);
}
}
示例2: speedometer
void * speedometer(void * argument) {
const timespec waitTime = { 0, MOUSE_SAMPLE_RATE };
cout << waitTime.tv_nsec << " " << waitTime.tv_sec << endl;
int fd;
struct input_event ie;
if ((fd = open(MOUSE_FILE, O_RDONLY)) == -1) {
perror("opening device");
// exit(1);
}
int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
int counter = 0;
while (true) {
//cout << "hello from the speedometer" << endl;
nanosleep(&waitTime, NULL);
//cout << "wait over" << endl;
counter = 0;
while (read(fd, &ie, sizeof(struct input_event)) != -1) {
//cout << "reading mouse" << endl;
if ((ie.type == 2) && (ie.code == 8)) {
counter++;
// cout << "new mouse event " << counter << endl;
}
}
//cout << "aquireing mutex" << endl;
//cout << "aquired mutex" << endl;
currentState.speed = (counter * MOUSE_MM_PER_CLICK) * 10; //mm/s
currentState.distanceTraveled = counter * MOUSE_MM_PER_CLICK; //mm.
//cout << "speed: " << currentState.speed << " distance: " << currentState.distanceTraveled << endl;
ptree answerJson;
stringstream jsonWriteStream;
answerJson.put("speed", currentState.speed);
answerJson.put("distanceTraveled", currentState.distanceTraveled);
write_json(jsonWriteStream, answerJson);
//cout << "sending speedometer" << endl;
//pthread_mutex_lock(&watchDog_mutex);
if (currentState.connected) {
websocket_server.send(currentState.client, jsonWriteStream.str(),
websocketpp::frame::opcode::text);
}
//pthread_mutex_unlock(&watchDog_mutex);
//cout << "released mutex" << endl;
}
return 0;
}
示例3: on_message
//.........这里部分代码省略.........
currentState.leftTurn = false;
//cout << "Right turn signal off." << endl;
} else {
currentState.rightTurn = true;
currentState.leftTurn = false;
//cout << "Right turn signal on." << endl;
}
}
//left
if (parsedJson.get<bool>("L1")) {
if (currentState.leftTurn == true) {
currentState.leftTurn = false;
currentState.rightTurn = false;
//cout << "Left turn signal off." << endl;
} else {
currentState.leftTurn = true;
currentState.rightTurn = false;
//cout << "Left turn signal on." << endl;
}
}
//check for peak
if (currentState.leftTurn || currentState.rightTurn) {
if (currentState.turnPeaked) {
if (currentState.servoInt == SERVO_CENTER) {
currentState.leftTurn = false;
currentState.rightTurn = false;
currentState.turnPeaked = false;
//cout << "Turn complete" << endl;
}
} else {
if (currentState.leftTurn) {
if (currentState.servoInt
< (SERVO_CENTER - TURN_THRESHOLD)) {
currentState.turnPeaked = true;
}
} else if (currentState.rightTurn) {
if (currentState.servoInt
> (SERVO_CENTER + TURN_THRESHOLD)) {
currentState.turnPeaked = true;
}
}
}
}
pthread_mutex_unlock(&turnSignal_mutex);
//toggle cruise mode
if (parsedJson.get<bool>("left")) {
if (currentState.cruise == true) {
currentState.cruise = false;
cout << "Cruise mode off" << endl;
} else {
currentState.cruise = true;
cout << "Cruise mode on" << endl;
}
}
if (parsedJson.get<bool>("up")) {
currentState.motorInt = currentState.motorInt + 10;
gpioServo(GPIO_MOTOR_CONTROL, currentState.motorInt);
//cout << "Current value of motorInt: " << currentState.motorInt << endl;
} else if (parsedJson.get<bool>("down")) {
currentState.motorInt = currentState.motorInt - 10;
gpioServo(GPIO_MOTOR_CONTROL, currentState.motorInt);
//cout << "Current value of motorInt: " << currentState.motorInt << endl;
}
}
pthread_mutex_unlock(&autonomous_mutex);
ptree answerJson;
stringstream jsonWriteStream;
answerJson.put("left_blinker", currentState.leftTurn);
answerJson.put("right_blinker", currentState.rightTurn);
write_json(jsonWriteStream, answerJson);
//cout << "sending speedometer" << endl;
if (currentState.connected) {
websocket_server.send(currentState.client, jsonWriteStream.str(),
websocketpp::frame::opcode::text);
}
//keep track of message recieved times.
unsigned long currentTime = time(NULL);
pthread_mutex_lock(&watchDog_mutex);
//cout << "currentTime=" << currentTime << endl;
currentState.lastMessageTime = currentTime;
currentState.connected = true;
pthread_mutex_unlock(&watchDog_mutex);
} catch (std::exception const& e) {
cerr << "<ERROR>" << endl;
cerr << e.what() << endl;
cerr << msg->get_payload() << endl;
cerr << "</ERROR>" << endl;
}
}
示例4: on_open
void on_open(connection_hdl hdl) {
holdThreads[hdl]=0;//just an example. Creates a new item for every connection. Gets deleted on close
m_server.send(hdl,"message", websocketpp::frame::opcode::text);
}