本文整理汇总了C++中server::listen方法的典型用法代码示例。如果您正苦于以下问题:C++ server::listen方法的具体用法?C++ server::listen怎么用?C++ server::listen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类server
的用法示例。
在下文中一共展示了server::listen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
////////////////////////init current state////////////////
currentState.connected = false;
currentState.autonomous = false;
currentState.cruise = false;
currentState.leftTurn = false;
currentState.rightTurn = false;
currentState.turnPeaked = false;
currentState.signalOn = false;
currentState.obsticle = false;
currentState.servoInt = 0;
currentState.motorInt = 0;
currentState.speed = 0;
currentState.lastMessageTime = 0;
currentState.distanceTraveled = 0;
currentState.lastRequestedMotorInt = 0;
currentState.sonarRange = 200;
currentState.cameraAngle = 0;
////////////////////////GPIO setup////////////////////////
int GPIOstatus;
int GPIOfrequencySteering;
int GPIOfrequencyMotor;
GPIOstatus = gpioInitialise(); //required for GPIO to function
if (GPIOstatus < 0) //did we succeed
{
fprintf(stderr, "pigpio initialisation failed.\n");
return 1;
}
//steering
gpioSetPWMrange(GPIO_STEERING_CONTROL, 255);
gpioSetPWMfrequency(GPIO_STEERING_CONTROL, 0);
GPIOfrequencySteering = gpioGetPWMfrequency(GPIO_STEERING_CONTROL);
int GPIOrangeSteering = gpioGetPWMrange(GPIO_MOTOR_CONTROL);
//motor
gpioSetPWMrange(GPIO_MOTOR_CONTROL, 255);
gpioSetPWMfrequency(GPIO_MOTOR_CONTROL, 250);
int GPIOrangeMotor = gpioGetPWMrange(GPIO_MOTOR_CONTROL);
GPIOfrequencyMotor = gpioGetPWMfrequency(GPIO_MOTOR_CONTROL);
cout << "FREQ: Using " << GPIOfrequencySteering << " for steering and "
<< GPIOfrequencyMotor << " for motor." << endl;
cout << "RANGE: Using " << GPIOrangeSteering << " for steering and "
<< GPIOrangeMotor << "for motor." << endl;
//gpioSetAlertFunc(GPIOsteeringControl, GPIOcallBack);
gpioServo(GPIO_STEERING_CONTROL, SERVO_CENTER); //set steering to straight
//set mode of turn signals to output
gpioSetMode(GPIO_RIGHT_TURN_SIGNAL, PI_OUTPUT);
gpioSetMode(GPIO_LEFT_TURN_SIGNAL, PI_OUTPUT);
/////////////////////////threads////////////////////////////
pthread_create(&watchDog_th, NULL, watchDog, NULL);
pthread_create(&turnSignal_th, NULL, turnSignal, NULL);
//pthread_create(&sonar_th, NULL, sonar, NULL);
pthread_create(&speedometer_th, NULL, speedometer, NULL);
pthread_create(&laneDetect_th, NULL, laneDetect, NULL);
pthread_create(&motorControl_th, NULL, motorControl, NULL);
////////////////////////Websocket Server setup////////////////////////
//what function should be called on a new message
websocket_server.set_message_handler(&on_message);//what function should be called on a new message
websocket_server.set_open_handler(&on_open);
websocket_server.set_close_handler(&on_close);
websocket_server.init_asio();
//What ip version and port should we listen on
websocket_server.listen(boost::asio::ip::tcp::v4(), 8080);
websocket_server.start_accept();
//Way to much log
websocket_server.clear_access_channels(websocketpp::log::alevel::all);
cout << "Starting RoadStar server" << endl;
websocket_server.run(); //start the server
gpioTerminate();
return 0;
}
示例2: run
void run(uint16_t port) {
m_server.listen(port);
m_server.start_accept();
m_server.run();
}